Hi all,
I’m working on redoing the matplotlib wxpython toolbar (https://github.com/matplotlib/matplotlib/issues/16701). As part of that, I’d like to start using their high resolution icons when available. However, I’m struggling with this. Let me just start by defining a high resolution screen as something where the GetContentScaleFactor() function returns >1 (on the screen I’m working with, a mac retina display, it returns 2).
At the moment I’m working on MacOS, but ideally I’d like a solution that works on all platforms.
The toolbar icons are 24x24 in normal size, 48x48 in large size.
Here’s what I have at the moment:
-
On MacOS, if you have icons with names like back.png and back@2x.png, if you’re on a high resolution screen it automatically grabs the @2x version, and does something either with resizing or virtual pixels to make it come out the right size. It’s basically magic to me, but it works fine.
-
The matplotlib resources (https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/mpl-data/images) don’t fit this naming convention, they instead have names like back.png and back_large.png.
-
If I rename back_large.png to back@2x.png it works great on MacOS. Image is correct size and sharp (i.e. StaticBitmap size is 24x24)
-
If I load the large image, it displays at the full size on my monitor, which means scaled up and fuzzy (i.e. StaticBitmap size is 48x48 instead of 24x24)
-
If I load the large image and scale it by 2, the image is the correct size and fuzzy (i.e. StaticBitmap size is 24x24).
-
When I load back.png on MacOS with a content scale factor of 2, so it’s really loading back@2x.png, the Bitmap size is 48x48 but the StaticBitmap created from it has a size of 24x24. When I load back_large.png on MacOS with a content scale factor of 2, the Bitmap size is 48x48 and the StaticBitmap created from it has a size of 48x48.
Point 6 makes me feel like there’s some magic scale variable somewhere that I’m missing, or something like that.
Is there a way to handle this in a platform independent (or dependent) way that doesn’t require renaming the matplotlib resources? I know that wxpython 4.10 is introducing some new ways of dealing with scaling, is this something that just has to wait for that release?
My current test platform:
MacOS 10.14
wxpython 4.07post2 (installed via conda from conda-forge)
Thanks!
- Jesse