From 192109386d58066b7c8ede5d1178a4b719c5f00c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 16 May 2022 15:27:16 -0700 Subject: [PATCH 1/5] Add convertFromPyObject code for wxBitmapBundle so we can autoconvert wxBitmaps from Python --- etg/bmpbndl.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/etg/bmpbndl.py b/etg/bmpbndl.py index a166b576c0..a1fab82695 100644 --- a/etg/bmpbndl.py +++ b/etg/bmpbndl.py @@ -40,6 +40,52 @@ def run(): c.find('FromSVG').findOverload('char *data, const wxSize &sizeDef').ignore() + # Allow on-the-fly creation of a wx.BitmapBundle from a wx.Bitmap, wx.Icon + # or a wx.Image + c.convertFromPyObject = """\ + // Check for type compatibility + if (!sipIsErr) { + if (sipCanConvertToType(sipPy, sipType_wxBitmap, SIP_NO_CONVERTORS)) + return 1; + if (sipCanConvertToType(sipPy, sipType_wxIcon, SIP_NO_CONVERTORS)) + return 1; + if (sipCanConvertToType(sipPy, sipType_wxImage, SIP_NO_CONVERTORS)) + return 1; + if (sipCanConvertToType(sipPy, sipType_wxBitmapBundle, SIP_NO_CONVERTORS)) + return 1; + return 0; + } + + // Otherwise, a conversion is needed + int state = 0; + if (sipCanConvertToType(sipPy, sipType_wxBitmap, SIP_NO_CONVERTORS)) { + wxBitmap* obj = reinterpret_cast( + sipConvertToType(sipPy, sipType_wxBitmap, sipTransferObj, SIP_NO_CONVERTORS, &state, sipIsErr)); + *sipCppPtr = new wxBitmapBundle(*obj); + sipReleaseType(obj, sipType_wxBitmap, state); + return sipGetState(sipTransferObj); + } + if (sipCanConvertToType(sipPy, sipType_wxIcon, SIP_NO_CONVERTORS)) { + wxIcon* obj = reinterpret_cast( + sipConvertToType(sipPy, sipType_wxIcon, sipTransferObj, SIP_NO_CONVERTORS, &state, sipIsErr)); + *sipCppPtr = new wxBitmapBundle(*obj); + sipReleaseType(obj, sipType_wxIcon, state); + return sipGetState(sipTransferObj); + } + if (sipCanConvertToType(sipPy, sipType_wxImage, SIP_NO_CONVERTORS)) { + wxImage* obj = reinterpret_cast( + sipConvertToType(sipPy, sipType_wxImage, sipTransferObj, SIP_NO_CONVERTORS, &state, sipIsErr)); + *sipCppPtr = new wxBitmapBundle(*obj); + sipReleaseType(obj, sipType_wxImage, state); + return sipGetState(sipTransferObj); + } + + // The final option is that it is already a wxBitmapBundle, so just fetch the pointer and return + *sipCppPtr = reinterpret_cast( + sipConvertToType(sipPy, sipType_wxBitmapBundle, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr)); + return 0; // not a new instance + """ + c = module.find('wxBitmapBundleImpl') assert isinstance(c, etgtools.ClassDef) From 56b790f50b88f5a9cd9e345c6094e2758b3ea223 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 16 May 2022 15:28:02 -0700 Subject: [PATCH 2/5] Add a couple more tests for wx.BitmapBundle --- unittests/test_bmpbndl.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/unittests/test_bmpbndl.py b/unittests/test_bmpbndl.py index db5a436cf0..d6882ebbcb 100644 --- a/unittests/test_bmpbndl.py +++ b/unittests/test_bmpbndl.py @@ -26,6 +26,24 @@ def test_BitmapBundleCtor4(self): b4 = wx.BitmapBundle(wx.Image(pngFile)) self.assertTrue( b4.IsOk() ) + def test_BitmapBundleVector(self): + bmps = [wx.Bitmap(16,16,32), + wx.Bitmap(24,24,32), + wx.Bitmap(32,32,32), + wx.Bitmap(64,64,32)] + bb = wx.BitmapBundle.FromBitmaps(bmps) + self.assertTrue( bb.IsOk() ) + b = bb.GetBitmap((32,32)) + self.assertTrue(b.IsOk()) + self.assertEquals(b.GetSize(), wx.Size(32,32)) + + def test_BitmapBundle_ImplicitCtor(self): + "Ensure that a wx.Bitmap can still be used where a wx.BitmapBundle is needed" + bmp = wx.Bitmap(pngFile) + btn = wx.Button(self.frame, -1, "Hello") + btn.SetBitmap(bmp) + + #--------------------------------------------------------------------------- if __name__ == '__main__': From a985c61011d4d998de2d48449a1d4195463d782b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 16 May 2022 15:28:23 -0700 Subject: [PATCH 3/5] Add changelog for wx.BitmapBundle --- CHANGES.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ce0a6f96cb..c48a801258 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,13 +18,13 @@ Pip: ``pip install wxPython==4.1.2`` New and improved in this release: -* Yes, it's been a long time since the last release. I'm not dead, just on an +* Yes, it's been a VERY long time since the last release. I'm not dead, just on an extended break. It took me a while to get up to speed on a new job, and then there was a seemingly perpetual crunch-mode to get the product through a couple releases. I can't say that things are fully back to normal yet, but at least I now know what I'm doing. Mostly. -* This release is built using wxWidgets code very near the wxWidgets' 3.1.5 +* This release is built using wxWidgets code very near the wxWidgets' 3.1.6 release tag. * Tweaked the build scripts a bit to ensure that on non-Windows platforms that @@ -54,6 +54,15 @@ New and improved in this release: * Fix 'More Grid Features' in demo +* Many of the widgets which deal with bitmaps have been changed to use a + wx.BitmapBundle object instead. This is the mechanism which wxWidgets has + implemented for adapting to things like Hi-DPI displays. Essentially you can + load a list of bitmaps of different sizes into a wx.BitmapBundle, and the + widget can choose one based on the display density. Existing code should be + able to continue to pass a wx.Bitmap to the widget constructor or to methods + like SetBitmap, as wxPython will automatically convert from a wx.Bitmap to a + wx.BitmapBundle where it is needed. + From f36358eaf29acef3fc9e737aee8deadacb056bf1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 16 May 2022 15:48:20 -0700 Subject: [PATCH 4/5] Fix some wxWidgets interface docs that were still specifying wxBitmap instead of wxBitmapBundle --- ext/wxWidgets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/wxWidgets b/ext/wxWidgets index 1990792484..3dcee0777e 160000 --- a/ext/wxWidgets +++ b/ext/wxWidgets @@ -1 +1 @@ -Subproject commit 19907924842a9152b8ee5f03f117aed65193b964 +Subproject commit 3dcee0777eeece2b4fa87a0368de9de86f5f4c05 From 70c767282cb8439eeb9a848d4f8a4d6ee91637f9 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 16 May 2022 15:56:03 -0700 Subject: [PATCH 5/5] Add a TODO --- etg/bmpbndl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etg/bmpbndl.py b/etg/bmpbndl.py index a1fab82695..a1d54c1df6 100644 --- a/etg/bmpbndl.py +++ b/etg/bmpbndl.py @@ -58,6 +58,7 @@ def run(): // Otherwise, a conversion is needed int state = 0; + // TODO: A macro for these nearly identical statements would be a good idea... if (sipCanConvertToType(sipPy, sipType_wxBitmap, SIP_NO_CONVERTORS)) { wxBitmap* obj = reinterpret_cast( sipConvertToType(sipPy, sipType_wxBitmap, sipTransferObj, SIP_NO_CONVERTORS, &state, sipIsErr));