
    gZ	                     6    d Z ddlmZmZmZmZ ddZd ZddZy)zA Defines utility functions for working with SVG documents in Qt.
    )QtCoreQtGuiQtSvg	QtWidgetsNc                    t        | t              r| j                  d      } t        j                  |d      }|j                  t        j                  j                         |j                  d       |j                  d       |j                         rC|j                         d   }t        |d      }	 |j                  |        |j                          |S y# |j                          w xY w)aj   Prompts the user to save an SVG document to disk.

    Parameters
    ----------
    string : basestring
        A Python string containing a SVG document.

    parent : QWidget, optional
        The parent to use for the file dialog.

    Returns
    -------
    The name of the file to which the document was saved, or None if the save
    was cancelled.
    utf-8zSave SVG DocumentsvgzSVG document (*.svg)r   wbN)
isinstancestrencoder   QFileDialogsetAcceptMode
AcceptSavesetDefaultSuffixsetNameFilterexec_selectedFilesopenwriteclose)stringparentdialogfilenamefs        -lib/python3.12/site-packages/qtconsole/svg.pysave_svgr      s      &#w'""6+>?F
..99:
E"
/0||~'')!,4 	GGFOGGI GGIs   3C C)c                     t        | t              r| j                  d      } t        j                         }|j                  d|        t        j                  j                         j                  |       y)z Copy a SVG document to the clipboard.

    Parameters
    ----------
    string : basestring
        A Python string containing a SVG document.
    r   zimage/svg+xmlN)
r   r   r   r   	QMimeDatasetDatar   QApplication	clipboardsetMimeData)r   	mime_datas     r   svg_to_clipboardr&   )   sW     &#w'  "Iov.$$&229=    c                    t        | t              r| j                  d      } t        j                  t        j                  |             }|j                         st        d      ||j                         }t        j                  |t        j                  j                        }|j                  d       t        j                  |      }|j                  |       |S )a   Convert a SVG document to a QImage.

    Parameters
    ----------
    string : basestring
        A Python string containing a SVG document.

    size : QSize, optional
        The size of the image that is produced. If not specified, the SVG
        document's default size is used.
    
    Raises
    ------
    ValueError
        If an invalid SVG string is provided.

    Returns
    -------
    A QImage of format QImage.Format_ARGB32.
    r   zInvalid SVG data.r   )r   r   r   r   QSvgRendererr   
QByteArrayisValid
ValueErrordefaultSizer   QImageFormat_ARGB32fillQPainterrender)r   sizerendererimagepainters        r   svg_to_imager7   8   s    * &#w'!!&"3"3F";<H,--|##%LLu||99:E	JJqMnnU#GOOGLr'   )N)	__doc__qtpyr   r   r   r   r   r&   r7    r'   r   <module>r;      s"    1 0B>"r'   