From 21fc134bd758dfb3586cff496d7e747eec5b0b03 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 28 Apr 2018 20:48:26 -0700 Subject: [PATCH] Merge pull request #832 from RobinD42/fix-issue820 Workaround the lack of checking valid page numbers in book ctrls --- CHANGES.rst | 3 +++ etg/bookctrl.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9b904982..84381309 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -102,6 +102,9 @@ Changes in this release include the following: * Change winid parameter in wx.ScrolledWindow to id, for consistency. (#816) +* 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)