diff --git a/demo/StatusBar.py b/demo/StatusBar.py index 5fe90434..64f45043 100644 --- a/demo/StatusBar.py +++ b/demo/StatusBar.py @@ -75,11 +75,10 @@ class CustomStatusBar(wx.StatusBar): # reposition the checkbox def Reposition(self): - # sw0 = self.GetStatusWidth(0) - sw1 = self.GetStatusWidth(1) - sw2 = self.GetStatusWidth(2) - sz = self.GetSize() - self.cb.SetPosition((sz[0] - sw2 - sw1 - 25, 4)) + rect = self.GetFieldRect(1) + rect.x += 1 + rect.y += 1 + self.cb.SetRect(rect) self.sizeChanged = False diff --git a/etg/statusbar.py b/etg/statusbar.py index a89a74f2..8a62de3a 100644 --- a/etg/statusbar.py +++ b/etg/statusbar.py @@ -31,6 +31,7 @@ def run(): # customizing the generated code and docstrings. c = module.find('wxStatusBar') + assert isinstance(c, etgtools.ClassDef) tools.fixWindowClass(c) module.addGlobalStr('wxStatusBarNameStr', c) @@ -46,6 +47,17 @@ def run(): self->SetStatusWidths(widths->size(), ptr); """) + # Change GetFieldRect to return the rectangle (for Pythonicity and Classic compatibility) + c.find('GetFieldRect').ignore() + c.addCppMethod('wxRect*', 'GetFieldRect', '(int i)', + doc="Returns the size and position of a field's internal bounding rectangle.", + body="""\ + wxRect* r = new wxRect; + self->GetFieldRect(i, *r); + return r; + """) + + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/unittests/test_statusbar.py b/unittests/test_statusbar.py index 591f5464..053b1195 100644 --- a/unittests/test_statusbar.py +++ b/unittests/test_statusbar.py @@ -89,6 +89,16 @@ class statusbar_Tests(wtc.WidgetTestCase): widths = [sb.GetStatusWidth(i) for i in range(sb.GetFieldsCount())] self.assertEqual(widths, [200, -1, 100]) + + def test_statusbarGetFielRect(self): + # Test that GetFieldRect has been tweaked to be compatible with Classic + sb = self.frame.CreateStatusBar(3) + self.frame.SetStatusWidths([200, -1, 100]) + + r = sb.GetFieldRect(1) + self.assertTrue(isinstance(r, wx.Rect)) + + #---------------------------------------------------------------------------