From e4f473bf1dababe012c771d110ec6792543eb478 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 28 Apr 2018 19:48:14 -0700 Subject: [PATCH] Workaround the lack of checking valid page numbers in book ctrls --- CHANGES.rst | 4 ++++ etg/bookctrl.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index d92b59c3..978aa195 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -67,6 +67,10 @@ Changes in this release include the following: * Fix wxGet to be able to use pip v10. (#817) +* Ensure that the page exists in book controls GetPage and RemovePage methods. + At least one of the wx ports do not do this. (#830) + + diff --git a/etg/bookctrl.py b/etg/bookctrl.py index 5948e2c9..7c56a74f 100644 --- a/etg/bookctrl.py +++ b/etg/bookctrl.py @@ -42,6 +42,21 @@ def run(): c.find('HitTest.flags').out = True + # Workaround the lack of checking valid page numbers in wxGTK. + c.addPyCode("""\ + def _checkBookPageCount(f): + import functools + @functools.wraps(f) + def wrapper(self, page): + if page >= self.GetPageCount(): + raise wx.PyAssertionError("invalid notebook page") + return f(self, page) + return wrapper + + BookCtrlBase.RemovePage = _checkBookPageCount(BookCtrlBase.RemovePage) + BookCtrlBase.GetPage = _checkBookPageCount(BookCtrlBase.GetPage) + """) + #----------------------------------------------------------------- tools.doCommonTweaks(module)