Button 如何创建带有SVG图标的wxPython按钮?
我面临着反对的警告Button 如何创建带有SVG图标的wxPython按钮?,button,svg,wxpython,Button,Svg,Wxpython,我面临着反对的警告 wxPyDeprecationWarning: Call to deprecated item ImageFromStream. Use :class:`Image` instead. svgimg = wx.ImageFromStream(StringIO.StringIO(svgpng),wx.BITMAP_TYPE_PNG) wxPyDeprecationWarning: Call to deprecated item BitmapFromImage. Use :c
wxPyDeprecationWarning: Call to deprecated item ImageFromStream. Use :class:`Image` instead.
svgimg = wx.ImageFromStream(StringIO.StringIO(svgpng),wx.BITMAP_TYPE_PNG)
wxPyDeprecationWarning: Call to deprecated item BitmapFromImage. Use :class:`wx.Bitmap` instead
svgbmp = wx.BitmapFromImage(svgimg)
为了
我似乎找不到关于如何为按钮创建SVG图标的信息(说明图标应该是位图,考虑到SVG存在的时间,这似乎有点过时)和。也只提到位图
即使我必须使用位图,我也希望消除弃用警告
我使用的是源代码在Ubuntu 16.10上构建的Phoenix 9b743cf3(他们无法使用git标签)。警告告诉您如何更正它
wx.Image
可以接受流作为第一个参数(而不是wx.ImageFromStream
),而wx.Bitmap
可以接受wx.Image
作为第一个参数(而不是wx.BitmapFromImage
)
另见
def getBmpFromSvg(self,svgxml, width, height):
"""
Credit goes to https://cyberxml.wordpress.com/2015/02/17/wxpython-wx-bitmap-icons-from-svg-xml/. Asked https://cyberxml.wordpress.com/2015/02/17/wxpython-wx-bitmap-icons-from-svg-xml/comment-page-1/#comment-11 to a version avoiding deprecated wx.BitmapFromImage.
"""
svgpng = cairosvg.svg2png(svgxml)
svgimg = wx.ImageFromStream(StringIO.StringIO(svgpng),wx.BITMAP_TYPE_PNG)
svgimg = svgimg.Scale(width, height, wx.IMAGE_QUALITY_HIGH)
svgbmp = wx.BitmapFromImage(svgimg)
return svgbmp
playButtonImg = self.getBmpFromSvg(resource_string("[name]", os.path.join("resources", "icons", 'play-button.svg')), icon_size_default, icon_size_default)
self.playButton = buttons.GenBitmapButton(self.videoPanel, bitmap=playButtonImg, name="play")