
     h                     P    d Z ddlZddlmZmZ ddlmZ ddlmZ  G d dee      Z	y)a  
The *Drawing* object is the overall container for all SVG
elements. It provides the methods to store the drawing into a file or a
file-like object. If you want to use stylesheets, the reference links
to this stylesheets were also stored (`add_stylesheet`)
in the *Drawing* object.

set/get SVG attributes::

    element['attribute'] = value
    value = element['attribute']

The Drawing object also includes a defs section, add elements to the defs
section by::

    drawing.defs.add(element)

    N)SVGDefs)ElementFactory)
pretty_xmlc                   T     e Zd ZdZd	 fd	Z fdZd
dZddZddZddZ	d Z
 xZS )Drawinga   This is the SVG drawing represented by the top level *svg* element.

    A drawing consists of any number of SVG elements contained within the drawing
    element, stored in the *elements* attribute.

    A drawing can range from an empty drawing (i.e., no content inside of the drawing),
    to a very simple drawing containing a single SVG element such as a *rect*,
    to a complex, deeply nested collection of container elements and graphics elements.
    c                 L    t        t        | 
  dd|i| || _        g | _        y)a  
        :param string filename: filesystem filename valid for :func:`open`
        :param 2-tuple size: width, height
        :param keywords extra: additional svg-attributes for the *SVG* object

        Important (and not SVG Attributes) **extra** parameters:

        :param string profile: ``'tiny | full'`` - define the SVG baseProfile
        :param bool debug: switch validation on/off

        sizeN )superr   __init__filename_stylesheets)selfr   r
   extra	__class__s       l/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/svgwrite/drawing.pyr   zDrawing.__init__+   s+     	gt%94959     c                     | j                   }| j                  }d| j                  d<   d| j                  d<   d| j                  d<   || j                  d<   || j                  d<   t        t        |          S )	z Get the XML representation as `ElementTree` object.

        :return: XML `ElementTree` of this object and all its subelements

        zhttp://www.w3.org/2000/svgxmlnszhttp://www.w3.org/1999/xlinkzxmlns:xlinkz!http://www.w3.org/2001/xml-eventszxmlns:evbaseProfileversion)profiler   attribsr   r   get_xml)r   r   r   r   s      r   r   zDrawing.get_xml;   sm     ,,,, <W&D]##FZ &-]#")YWd+--r   c                 B    | j                   j                  ||||f       y)a5   Add a stylesheet reference.

        :param string href: link to stylesheet <URI>
        :param string title: name of stylesheet
        :param string alternate: ``'yes'|'no'``
        :param string media: ``'all | aureal | braille | embossed | handheld | print | projection | screen | tty | tv'``

        N)r   append)r   hreftitle	alternatemedias        r   add_stylesheetzDrawing.add_stylesheetK   s!     	  $y%!@Ar   c                     |j                  d       d}| j                  D ]  }|j                  ||z          | j                         }|rt        ||      }|j                  |       y)aK   Write XML string to `fileobj`.

        :param fileobj: a file-like object
        :param pretty: True for easy readable output
        :param indent: how much to indent if pretty is enabled, by default 2 spaces

        Python 3.x - set encoding at the open command::

            open('filename', 'w', encoding='utf-8')
        z(<?xml version="1.0" encoding="utf-8" ?>
zR<?xml-stylesheet href="%s" type="text/css" title="%s" alternate="%s" media="%s"?>
)indentN)writer   tostringr   )r   fileobjprettyr$   stylesheet_template
stylesheet
xml_strings          r   r%   zDrawing.writeV   sj     	AB
7 ++ 	<JMM-
:;	< ]]_
#Jv>Jj!r   c                     t        j                  | j                  dd      }| j                  |||       |j	                          y)z Write the XML string to `self.filename`.

        :param pretty: True for easy readable output
        :param indent: how much to indent if pretty is enabled, by default 2 spaces
        wzutf-8)modeencodingr(   r$   N)ioopenr   r%   close)r   r(   r$   r'   s       r   savezDrawing.saver   s5     ''$--cGD

76&
9r   c                 8    || _         | j                  ||       y)a   Write the XML string to `filename`.

        :param string filename: filesystem filename valid for :func:`open`
        :param pretty: True for easy readable output
        :param indent: how much to indent if pretty is enabled, by default 2 spaces
        r0   N)r   r4   )r   r   r(   r$   s       r   saveaszDrawing.saveas|   s     !			/r   c                 "    | j                         S )z Show SVG in IPython, Jupyter Notebook, and Jupyter Lab

        :return: unicode XML string of this object and all its subelements

        )r&   )r   s    r   
_repr_svg_zDrawing._repr_svg_   s     }}r   )z
noname.svg)100%r9   )noscreen)F   )__name__
__module____qualname____doc__r   r   r"   r%   r4   r6   r8   __classcell__)r   s   @r   r   r   !   s,     . 	B"80r   r   )
r@   r1   svgwrite.containerr   r   svgwrite.elementfactoryr   svgwrite.utilsr   r   r   r   r   <module>rE      s(   $ 
 ( 2 %kc> kr   