Retina images in wxPython

177 views
Skip to first unread message

Rishi Sharma

unread,
May 22, 2017, 3:13:29 PM5/22/17
to wxpytho...@googlegroups.com
Hi everyone,

I understand wxPython has support for retina text, but no matter what I do I cannot get retina support working for images.

Does anyone have an idea on how to get it to work if possible? Do I need to patch wxWidgets and rebuild wxPython?  Whats the least version that supports retina?

If anyone has a sample demo script that works I'd appreciate an example.

Thanks,

-R

Igor Korot

unread,
May 22, 2017, 3:20:27 PM5/22/17
to wxpytho...@googlegroups.com
Hi,
What is your {wx}python versions?
What OSX version?
Are you sure you have a Retina display?

Thank you.

>
> Thanks,
>
> -R
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Rishi Sharma

unread,
May 22, 2017, 4:02:56 PM5/22/17
to wxpytho...@googlegroups.com
Hi!

I have a Macbook Pro Retina Touchbar.  I made sure the screen is set to Default.

This is what I have found so far.  I'm using wxPython 3.0.1.0 (although I've tried to use the 4.0 version as well).  Below is a sample script I wrote (requires AppKit PyObjC to check for backingScaleFactor).  I made sure to look at the backingScaleFactor and found it correctly it returns 2.  I'm looking at the bitmap code block and do see support:

        if  ( type == wxBITMAP_TYPE_PNG )
        {
            if ( wxOSXGetMainScreenContentScaleFactor() > 1.9 )
            {
                wxFileName fn(filename);
                fn.MakeAbsolute();
                fn.SetName(fn.GetName()+"@2x");
                
                if ( fn.Exists() )
                {
                    fname = fn.GetFullPath();
                    scale = 2.0;
                }
            }
        }

I just have no idea why its not working.  Here is the sample:

import AppKit as AK
import wx

class MyFrame(wx.Frame):
  def __init__(self, parent):
    wx.Frame.__init__(self, parent, -1, "Retina Demo")
    print AK.NSScreen.screens()[0].backingScaleFactor()
    path = "img.png"
    bmp = wx.EmptyBitmap( 1, 1 )
    bmp.LoadFile(path, wx.BITMAP_TYPE_PNG)
    bmp = wx.StaticBitmap(self, -1, bmp)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(bmp, 1, wx.ALL|wx.EXPAND, 5)
    self.SetSizer(sizer)
    sizer.Fit(self)
    self.Layout()

app = wx.App()
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()


> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

Rishi Sharma

unread,
May 22, 2017, 4:03:51 PM5/22/17
to wxpytho...@googlegroups.com
In order to test it uses the correct image, I have img.png and i...@2x.png (both are actually different images so I can tell which one is loaded).

Igor Korot

unread,
May 22, 2017, 4:11:42 PM5/22/17
to wxpytho...@googlegroups.com
Hi,

On Mon, May 22, 2017 at 4:03 PM, Rishi Sharma <rishs...@gmail.com> wrote:
> In order to test it uses the correct image, I have img.png and i...@2x.png
> (both are actually different images so I can tell which one is loaded).

Are they both accessible?
Just for the test - can you try to load both of them and check that
the bitmap IsOk()
returns true?

Thank you.
>>> > email to wxpython-user...@googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "wxPython-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to wxpython-user...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.

Rishi Sharma

unread,
May 22, 2017, 4:44:36 PM5/22/17
to wxpytho...@googlegroups.com
On Mon, May 22, 2017 at 1:11 PM, Igor Korot <ikor...@gmail.com> wrote:
Hi,

On Mon, May 22, 2017 at 4:03 PM, Rishi Sharma <rishs...@gmail.com> wrote:
> In order to test it uses the correct image, I have img.png and i...@2x.png
> (both are actually different images so I can tell which one is loaded).

Are they both accessible?
Just for the test - can you try to load both of them and check that
the bitmap IsOk()
returns true?

Done, both return True.  Are you able to get the 2x image loaded with the script below (using substitute images)?
 

Thank you.

>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "wxPython-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an

>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

Igor Korot

unread,
May 22, 2017, 4:57:04 PM5/22/17
to wxpytho...@googlegroups.com
Hi,

On Mon, May 22, 2017 at 4:44 PM, Rishi Sharma <rishs...@gmail.com> wrote:
>
>
> On Mon, May 22, 2017 at 1:11 PM, Igor Korot <ikor...@gmail.com> wrote:
>>
>> Hi,
>>
>> On Mon, May 22, 2017 at 4:03 PM, Rishi Sharma <rishs...@gmail.com>
>> wrote:
>> > In order to test it uses the correct image, I have img.png and
>> > i...@2x.png
>> > (both are actually different images so I can tell which one is loaded).
>>
>> Are they both accessible?
>> Just for the test - can you try to load both of them and check that
>> the bitmap IsOk()
>> returns true?
>
>
> Done, both return True. Are you able to get the 2x image loaded with the
> script below (using substitute images)?

I don't have Mac with Retina.
Now you can successfully render the "@2" bitmap into the screen, right?
Maybe wxPython does not compile this code?

Thank you.
>> >>> > email to wxpython-user...@googlegroups.com.
>> >>> > For more options, visit https://groups.google.com/d/optout.
>> >>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "wxPython-users" group.
>> >>> To unsubscribe from this group and stop receiving emails from it, send
>> >>> an
>> >>> email to wxpython-user...@googlegroups.com.
>> >>> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "wxPython-users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to wxpython-user...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "wxPython-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to wxpython-user...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.

Rishi Sharma

unread,
May 22, 2017, 5:08:49 PM5/22/17
to wxpytho...@googlegroups.com
On Mon, May 22, 2017 at 1:56 PM, Igor Korot <ikor...@gmail.com> wrote:
Hi,

On Mon, May 22, 2017 at 4:44 PM, Rishi Sharma <rishs...@gmail.com> wrote:
>
>
> On Mon, May 22, 2017 at 1:11 PM, Igor Korot <ikor...@gmail.com> wrote:
>>
>> Hi,
>>
>> On Mon, May 22, 2017 at 4:03 PM, Rishi Sharma <rishs...@gmail.com>
>> wrote:
>> > In order to test it uses the correct image, I have img.png and
>> > i...@2x.png
>> > (both are actually different images so I can tell which one is loaded).
>>
>> Are they both accessible?
>> Just for the test - can you try to load both of them and check that
>> the bitmap IsOk()
>> returns true?
>
>
> Done, both return True.  Are you able to get the 2x image loaded with the
> script below (using substitute images)?

I don't have Mac with Retina.
Now you can successfully render the "@2" bitmap into the screen, right?
Maybe wxPython does not compile this code?

Yeah, but its rendered scaled up for the 2.0 factor.  I'm not sure how wxPython would not compile the code since it seems to be in the wxwidgets source included with it.  I did originally download the binary though, so perhaps something in the binary had it off.   

I can't find a single success story about retina and wxPython via google so not sure whats up.  
 

Thank you.

>> >>> > For more options, visit https://groups.google.com/d/optout.
>> >>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "wxPython-users" group.
>> >>> To unsubscribe from this group and stop receiving emails from it, send
>> >>> an

>> >>> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "wxPython-users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "wxPython-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

Igor Korot

unread,
May 22, 2017, 5:34:27 PM5/22/17
to wxpytho...@googlegroups.com
Hi,
It is possible that wxPython release (code cut-off) was done prior to
this specific code
was put into wxWidgets.

Try building the wxWidgets Git HEAD along with wxPython Git HEAD and see if it
works.

Thank you.
>> >> >>> > email to wxpython-user...@googlegroups.com.
>> >> >>> > For more options, visit https://groups.google.com/d/optout.
>> >> >>>
>> >> >>> --
>> >> >>> You received this message because you are subscribed to the Google
>> >> >>> Groups
>> >> >>> "wxPython-users" group.
>> >> >>> To unsubscribe from this group and stop receiving emails from it,
>> >> >>> send
>> >> >>> an
>> >> >>> email to wxpython-user...@googlegroups.com.
>> >> >>> For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >>
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "wxPython-users" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to wxpython-user...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "wxPython-users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to wxpython-user...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "wxPython-users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to wxpython-user...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "wxPython-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to wxpython-user...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.

Rishi Sharma

unread,
May 22, 2017, 5:37:57 PM5/22/17
to wxpytho...@googlegroups.com
I checked the source for that version: https://cytranet.dl.sourceforge.net/project/wxpython/wxPython/3.0.1.0/wxPython-src-3.0.1.0.tar.bz2 and the code block is in there.

Additionally I tried the same script with 4.0a and it doesn't work either (which undoubtedly would have the changes).

I'm trying to build that version but keep getting errors in wxWidgets.  I guess I'm missing the "ar" utility need to build it.  So more googling.




>> >> >>> > For more options, visit https://groups.google.com/d/optout.
>> >> >>>
>> >> >>> --
>> >> >>> You received this message because you are subscribed to the Google
>> >> >>> Groups
>> >> >>> "wxPython-users" group.
>> >> >>> To unsubscribe from this group and stop receiving emails from it,
>> >> >>> send
>> >> >>> an

>> >> >>> For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >>
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "wxPython-users" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an

>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "wxPython-users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "wxPython-users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "wxPython-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

Rishi Sharma

unread,
Aug 10, 2017, 4:59:16 PM8/10/17
to wxpytho...@googlegroups.com
For anyone who is having this problem, do not use the distributed version.  Instead download the source and recompile.  This fixed the problem for me.

itsay...@gmail.com

unread,
May 19, 2018, 5:05:29 PM5/19/18
to wxPython-users
Rish, just out of curiosity, when you recompiled, did you have to enable wxUSE_IMAGE yourself?  It looks like the wxPython build script doesn't use this option, and it also looks necessary for the @2x code in wxWidgets.

thanks!
Matt
>> >> >>> > email to wxpython-user...@googlegroups.com.

>> >> >>> > For more options, visit https://groups.google.com/d/optout.
>> >> >>>
>> >> >>> --
>> >> >>> You received this message because you are subscribed to the Google
>> >> >>> Groups
>> >> >>> "wxPython-users" group.
>> >> >>> To unsubscribe from this group and stop receiving emails from it,
>> >> >>> send
>> >> >>> an

>> >> >>> For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >>
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "wxPython-users" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an

>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "wxPython-users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "wxPython-users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "wxPython-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

Robin Dunn

unread,
May 21, 2018, 2:52:07 PM5/21/18
to wxPython-users
On Saturday, May 19, 2018 at 2:05:29 PM UTC-7, itsay...@gmail.com wrote:
Rish, just out of curiosity, when you recompiled, did you have to enable wxUSE_IMAGE yourself?  It looks like the wxPython build script doesn't use this option, and it also looks necessary for the @2x code in wxWidgets.

wxUSE_IMAGE should be turned on by default.

 --
Robin

Reply all
Reply to author
Forward
0 new messages