如何使用SVG图标创建wxPython按钮?

时间:2017-04-04 20:55:38

标签: 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 :class:`wx.Bitmap` instead
 svgbmp = wx.BitmapFromImage(svgimg)

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")

我似乎没有找到有关如何为Icon's documentation按钮创建SVG图标的信息(说明图标应该是位图,考虑到SVG的时间,这看起来有点过时)和the icons overviewButton's documentation也提到了位图。

即使我必须使用位图,我也想删除弃用警告。

我正在使用Phoenix 9b743cf3(它们无法使用git标签)从Ubuntu 16.10上的源代码构建。

1 个答案:

答案 0 :(得分:1)

警告告诉您如何纠正它。 wx.Image可以接受第一个参数的流(而不是wx.ImageFromStream),而wx.Bitmap可以接受wx.Image作为第一个参数(而不是wx.BitmapFromImage

另见wx.Image.ConvertToBitmap