Merge pull request #438 from RobinD42/fix-issue426

Give DLG_UNIT some "elegance" ;-)
This commit is contained in:
Robin Dunn
2017-07-22 00:25:12 -07:00
committed by GitHub
2 changed files with 32 additions and 18 deletions

View File

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

View File

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