Workaround the lack of checking valid page numbers in book ctrls

This commit is contained in:
Robin Dunn
2018-04-28 19:48:14 -07:00
parent 3123b7ea23
commit e4f473bf1d
2 changed files with 19 additions and 0 deletions

View File

@@ -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)

View File

@@ -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)