From c44aca24f0732afab3134d94b4bbc2f3556a65f7 Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Sat, 30 Jul 2016 20:52:44 -0400 Subject: [PATCH 1/3] Fix a couple of imports in unittests --- unittests/test_lib_plot.py | 2 +- unittests/test_lib_throbber.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_lib_plot.py b/unittests/test_lib_plot.py index b6ad5c25..a2face6e 100644 --- a/unittests/test_lib_plot.py +++ b/unittests/test_lib_plot.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import unittest -import wtc +from unittests import wtc import wx import wx.lib.plot as wxplot diff --git a/unittests/test_lib_throbber.py b/unittests/test_lib_throbber.py index 3bc2bbcd..1b673b6c 100644 --- a/unittests/test_lib_throbber.py +++ b/unittests/test_lib_throbber.py @@ -4,7 +4,7 @@ import wx import wx.lib.throbber as th -import throbImages +from unittests import throbImages #--------------------------------------------------------------------------- From 054067ae71dfb630081376accecb8e5668dd0e84 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 2 Aug 2016 10:50:07 -0700 Subject: [PATCH 2/3] Don't set the id parameter default to wx.ID_ANY if there is a default. --- etgtools/tweaker_tools.py | 2 +- unittests/test_cshelp.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 9596eadc..1b99145a 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -239,7 +239,7 @@ def fixWindowClass(klass, hideVirtuals=True, ignoreProtected=True): parent.transferThis = True # if there is an id param give it a default id = func.findItem('id') or func.findItem('winid') - if id: + if id and not id.default: id.default = 'wxID_ANY' # if there is a pos or size parameter without a default then give it one. diff --git a/unittests/test_cshelp.py b/unittests/test_cshelp.py index 6eb6910a..bb4e4600 100644 --- a/unittests/test_cshelp.py +++ b/unittests/test_cshelp.py @@ -13,7 +13,10 @@ class cshelp_Tests(wtc.WidgetTestCase): pnl = wx.Panel(self.frame) pnl.SetHelpText("HelpMe!") cBtn = wx.ContextHelpButton(pnl) - + + # Make sure we haven't borked the magic ID + assert cBtn.GetId() == wx.ID_CONTEXT_HELP + def test_cshelp2(self): wx.wxEVT_HELP From 8a0571207b82fe91f30855d65096f55bf06e2ce4 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 2 Aug 2016 11:02:54 -0700 Subject: [PATCH 3/3] Add DLG_UNIT helper, with deprecated wrappers for DLG_SZE and DLG_PNT. Update the demo. --- demo/DialogUnits.py | 17 +++++++++-------- etg/window.py | 26 ++++++++++++++++++++++++-- unittests/test_window.py | 27 ++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/demo/DialogUnits.py b/demo/DialogUnits.py index 1dd7161f..5acda83b 100644 --- a/demo/DialogUnits.py +++ b/demo/DialogUnits.py @@ -32,25 +32,26 @@ class MyFrame(wx.Frame): panel = wx.Panel(self, -1) wx.StaticText(panel, -1, "Size:", - wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize + panel.DLG_UNIT((4, 4)), wx.DefaultSize ) wx.StaticText(panel, -1, "Pos:", - wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize + panel.DLG_UNIT((4, 20)), wx.DefaultSize ) self.sizeCtrl = wx.TextCtrl(panel, -1, "", - wx.DLG_PNT(panel, (24, 4)), - wx.DLG_SZE(panel, (36, -1)), + panel.DLG_UNIT((24, 4)), + panel.DLG_UNIT((36, -1)), wx.TE_READONLY) self.posCtrl = wx.TextCtrl(panel, -1, "", - wx.DLG_PNT(panel, (24, 16)), - wx.DLG_SZE(panel, (36, -1)), + panel.DLG_UNIT((24, 20)), + panel.DLG_UNIT((36, -1)), wx.TE_READONLY) - #print(wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1))) - #print(wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1))) + #print(wx.DLG_UNIT(panel, (24, 4)), wx.DLG_UNIT(panel, (36, -1))) + #print(panel.DLG_UNIT((24, 16)), panel.DLG_UNIT((36, -1))) + # This method is called automatically when the CLOSE event is # sent to this window diff --git a/etg/window.py b/etg/window.py index 222c805b..832e930f 100644 --- a/etg/window.py +++ b/etg/window.py @@ -194,8 +194,16 @@ def run(): self.Hide() wx.GetApp().ScheduleForDestruction(self) """) - - + + c.addPyMethod('DLG_UNIT', '(self, dlg_unit)', + doc="""\ + A convenience wrapper for :meth:`ConvertDialogToPixels`. + """, + body="""\ + return self.ConvertDialogToPixels(dlg_unit) + """) + + # MSW only. Do we want them wrapped? c.find('GetAccessible').ignore() c.find('SetAccessible').ignore() @@ -333,6 +341,20 @@ def run(): def __exit__(self, exc_type, exc_val, exc_tb): self._win.Thaw() ''') + + module.addPyCode('''\ + 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. + """ + if val2 is not None: + dlg_unit = (dlg_unit, val2) + return win.ConvertDialogToPixels(dlg_unit) + + DLG_PNT = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.") + DLG_SZE = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.") + ''') # Add a wrapper for wxWindowList and a new iterator class for it that diff --git a/unittests/test_window.py b/unittests/test_window.py index 50903bd6..ec977a24 100644 --- a/unittests/test_window.py +++ b/unittests/test_window.py @@ -100,7 +100,32 @@ class WindowTests(wtc.WidgetTestCase): self.assertEqual(a[1], b.y) self.assertEqual(c[0], d.x) self.assertEqual(c[1], d.y) - + + + def test_DLG_UNIT(self): + def _check(val): + a, b = val + assert isinstance(a, int) + assert isinstance(b, int) + + val = wx.DLG_UNIT(self.frame, wx.Point(10,10)) + _check(val) + val = wx.DLG_UNIT(self.frame, wx.Size(10,10)) + _check(val) + val = wx.DLG_UNIT(self.frame, (10,10)) + _check(val) + + 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) + + wx.DLG_SZE + wx.DLG_PNT + + #---------------------------------------------------------------------------