[英]Python: copy svg string to “image/svg+xml” format in windows clipboard, so can paste it as an svg image
说我有一个svg文件的xml内容,如下所示:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Created with matplotlib (http://matplotlib.org/) -->
<svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
...
我的问题是,如何将此字符串复制到Windows剪贴板中,而不是作为字符串而是复制为“ image / svg + xml”数据类型,可以将其作为svg图像粘贴到powerpoint中?
我知道的唯一支持Mime类型的剪贴板库是QtClipboard: https ://doc.qt.io/qtforpython/PySide2/QtGui/QClipboard.html
您可能想看看它。
您可以使用setMimeData
设置的Mime类型中也可能有image / svg + xml
例:
from PyQt5 import QtCore
d = QtCore.QMimeData()
print(d.formats()) # Now it is an empty list "[]" because you still didn't set the data and the mime type
# Set data in the object with the required mime type
d.setData("image/svg+xml", b'<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><!-- Created with matplotlib (http://matplotlib.org/) --><svg height="344.88pt" version="1.1" viewBox="0 0 460.8 344.88" width="460.8pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">')
print(d.formats()) # Now it prints: ['image/svg+xml']
从这里您可以将其带到QClipboard。
我引用了文档: http : //doc.qt.io/archives/qt-4.8/qclipboard.html
setMimeData()函数具有最大的灵活性:它允许您将任何QMimeData添加到剪贴板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.