Embed an SVG into the display. Note if you just want to view a svg image via a URL use `:class:Image` with a url=URL keyword argument.
| 752 | |
| 753 | |
| 754 | class SVG(DisplayObject): |
| 755 | """Embed an SVG into the display. |
| 756 | |
| 757 | Note if you just want to view a svg image via a URL use `:class:Image` with |
| 758 | a url=URL keyword argument. |
| 759 | """ |
| 760 | |
| 761 | _read_flags = 'rb' |
| 762 | # wrap data in a property, which extracts the <svg> tag, discarding |
| 763 | # document headers |
| 764 | _data = None |
| 765 | |
| 766 | @property |
| 767 | def data(self): |
| 768 | return self._data |
| 769 | |
| 770 | @data.setter |
| 771 | def data(self, svg): |
| 772 | if svg is None: |
| 773 | self._data = None |
| 774 | return |
| 775 | # parse into dom object |
| 776 | from xml.dom import minidom |
| 777 | x = minidom.parseString(svg) |
| 778 | # get svg tag (should be 1) |
| 779 | found_svg = x.getElementsByTagName('svg') |
| 780 | if found_svg: |
| 781 | svg = found_svg[0].toxml() |
| 782 | else: |
| 783 | # fallback on the input, trust the user |
| 784 | # but this is probably an error. |
| 785 | pass |
| 786 | svg = cast_unicode(svg) |
| 787 | self._data = svg |
| 788 | |
| 789 | def _repr_svg_(self): |
| 790 | return self._data_and_metadata() |
| 791 | |
| 792 | class ProgressBar(DisplayObject): |
| 793 | """Progressbar supports displaying a progressbar like element |