简体   繁体   中英

wxPython (Phoenix) retina status icon

I am trying to built wxPython app for Mac OS X (El Capitan) and working on MBP with retina display.

I just copied Google Drive app status icons - 16x16 and 32x32 (2x) and get it blurry.

I also tried code from this ticket and it doesn't help.

My code looks like this:

icon = wx.Icon('icon@2x.png', wx.BITMAP_TYPE_ANY)

And result (most left icon is mine):

在此处输入图片说明

wxPython version: 3.0.3.dev1836+f764b32 osx-cocoa (phoenix)

PS. I know that Google Drive built on wxPython too. but it have good retina images in status bar. How they do it?

One way is to check the scale before setting icon:

    import sys; print sys.version
    import wx; print wx.version()
    if 'phoenix' not in wx.PlatformInfo: exit()


    class CreateTestFrame(wx.Frame):
        def __init__(self):
            return wx.Frame.__init__(self, None, -1, "test frame")


    wxSandbox = wx.App()

    testFrame = CreateTestFrame()
    print "Scale factor: ", testFrame.GetContentScaleFactor()

    if testFrame.GetContentScaleFactor() < 2.0:
        print "Not 'Retina' scaling"
        icon = wx.Icon('./icons/mac-normal.png', wx.BITMAP_TYPE_ANY)
        print "pixel height", icon.GetHeight()
    else:
        print "'Retina' scaling"
        icon = wx.Icon('./icons/mac-normal@2x.png', wx.BITMAP_TYPE_ANY)
        print "pixel height", icon.GetHeight()
    testFrame.SetIcon(icon)
    testFrame.Show()
    wxSandbox.MainLoop()
    exit()

The scale on my display is showing as '2.0' and it correctly selects the 32x32 icon.

2.7.11 (default, Dec 5 2015, 14:44:53)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)]
'3.0.3(thorr18)-f764b32 osx-cocoa (phoenix)'
Scale factor: 2.0
'Retina' scaling
pixel height 32

Process finished with exit code 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM