diff --git a/etg/window.py b/etg/window.py index 007d70b5..b2fe867e 100644 --- a/etg/window.py +++ b/etg/window.py @@ -202,7 +202,11 @@ def run(): A convenience wrapper for :meth:`ConvertDialogToPixels`. """, body="""\ - return self.ConvertDialogToPixels(dlg_unit) + is_wxType = isinstance(dlg_unit, (wx.Size, wx.Point)) + pix = self.ConvertDialogToPixels(dlg_unit) + if not is_wxType: + pix = tuple(pix) + return pix """) @@ -359,11 +363,16 @@ def run(): def DLG_UNIT(win, dlg_unit, val2=None): """ Convenience function for converting a wx.Point, wx.Size or - (x,y) in dialog units to pixels. + (x,y) in dialog units to pixels, using the given window as a + reference. """ if val2 is not None: dlg_unit = (dlg_unit, val2) - return win.ConvertDialogToPixels(dlg_unit) + is_wxType = isinstance(dlg_unit, (wx.Size, wx.Point)) + pix = win.ConvertDialogToPixels(dlg_unit) + if not is_wxType: + pix = tuple(pix) + return pix DLG_PNT = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.") DLG_SZE = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.") diff --git a/unittests/test_window.py b/unittests/test_window.py index de9ccec1..1f82132f 100644 --- a/unittests/test_window.py +++ b/unittests/test_window.py @@ -103,31 +103,36 @@ class WindowTests(wtc.WidgetTestCase): def test_DLG_UNIT(self): - def _check(val): + def _check(val, typ): + assert isinstance(val, typ) a, b = val assert isinstance(a, int) assert isinstance(b, int) val = wx.DLG_UNIT(self.frame, wx.Point(10,10)) - _check(val) + _check(val, wx.Point) + val = wx.DLG_UNIT(self.frame, wx.Size(10,10)) - _check(val) + _check(val, wx.Size) + val = wx.DLG_UNIT(self.frame, (10,10)) - _check(val) + _check(val, tuple) + + val = wx.DLG_UNIT(self.frame, [10,10]) + _check(val, tuple) val = self.frame.DLG_UNIT(wx.Point(10, 10)) - _check(val) - val = self.frame.DLG_UNIT(wx.Size(10, 10)) - _check(val) - val = self.frame.DLG_UNIT((10, 10)) - _check(val) + _check(val, wx.Point) + + val = self.frame.DLG_UNIT(wx.Size(10, 10)) + _check(val, wx.Size) + + val = self.frame.DLG_UNIT((10, 10)) + _check(val, tuple) + + val = self.frame.DLG_UNIT([10, 10]) + _check(val, tuple) - val = wx.DLG_UNIT(self.frame, wx.Point(10, 10)) - assert isinstance(val, wx.Point) - - val = wx.DLG_UNIT(self.frame, wx.Size(10, 10)) - assert isinstance(val, wx.Size) - wx.DLG_SZE wx.DLG_PNT