From ede75fdc8d88c78bb85891b5100085cf37454186 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 3 Dec 2016 15:59:52 -0800 Subject: [PATCH] Add context manager methods to wx.BusyCursor Fixes #196 --- etg/utils.py | 6 ++++++ unittests/test_utils.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/etg/utils.py b/etg/utils.py index 312bd4b0..afcef0be 100644 --- a/etg/utils.py +++ b/etg/utils.py @@ -70,6 +70,12 @@ def run(): module.find('wxGetOsVersion.major').out = True module.find('wxGetOsVersion.minor').out = True + c = module.find('wxBusyCursor') + # add context manager methods + c.addPyMethod('__enter__', '(self)', 'return self') + c.addPyMethod('__exit__', '(self, exc_type, exc_val, exc_tb)', 'pass') + + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/unittests/test_utils.py b/unittests/test_utils.py index 0dd9a465..83ebe9f9 100644 --- a/unittests/test_utils.py +++ b/unittests/test_utils.py @@ -29,7 +29,10 @@ class utils_Tests(wtc.WidgetTestCase): self.assertTrue( wx.IsBusy()) wx.EndBusyCursor() self.assertTrue(not wx.IsBusy()) - + + def test_utilsBusyCursor3(self): + with wx.BusyCursor(): + self.myYield() def test_utilsSomeOtherStuff(self): wx.GetBatteryState()