From 8fecc2b5f9572d8e03b4418f511b8b80268b3cc8 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 24 Apr 2012 00:15:33 +0000 Subject: [PATCH] * Rename the wrappers for the C++ wxPlatformInfo to wx.PlatformInformation. * Restore the wx.PlatformInfo tuple like it exists in Classic. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71270 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/MigrationGuide.txt | 22 ---------------------- etg/_core.py | 4 ++-- etg/pickers.py | 2 +- etg/platinfo.py | 7 +++---- src/core_ex.cpp | 14 ++++++++------ src/core_ex.py | 3 ++- unittests/test_aboutdlg.py | 2 +- unittests/test_dc.py | 6 +++--- unittests/test_deadobj.py | 2 +- unittests/test_dialog.py | 2 +- unittests/test_platinfo.py | 11 +++-------- unittests/test_process.py | 4 ++-- unittests/wtc.py | 2 +- 13 files changed, 28 insertions(+), 53 deletions(-) diff --git a/docs/MigrationGuide.txt b/docs/MigrationGuide.txt index 84571a86..58c8ae80 100644 --- a/docs/MigrationGuide.txt +++ b/docs/MigrationGuide.txt @@ -111,28 +111,6 @@ your encoding to Unicode before passing the text to the wx API. -wx.Platform, wx.PlatformInfo ----------------------------- - -wx.Platform has been renamed to wx.Port, and wx.PlatformInfo has been renamed -to wx.PortInfo. The reason for this change is that wrappers for a C++ class -named wxPlatformInfo have been added, and would have caused a name conflict -if the old wx.PlatformInfo had not been renamed. To make transitioning a -little easier, I've made instances of the new wx.PlatformInfo class act like -a Python sequence containing the same items as the old wx.PlatformInfo. So -that means that you can simply change things like this:: - - if 'wxMac' in wx.PlatformInfo: - ... - -to this:: - - if 'wxMac' in wx.PlatformInfo.Get(): - ... - - - - Font, Pen, and Brush Styles --------------------------- diff --git a/etg/_core.py b/etg/_core.py index 93a17047..6fec07c7 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -221,13 +221,13 @@ def run(): if wx.Port == '__WXMSW__': port = 'msw' elif wx.Port == '__WXMAC__': - if 'wxOSX-carbon' in wx.PortInfo: + if 'wxOSX-carbon' in wx.PlatformInfo: port = 'osx-carbon' else: port = 'osx-cocoa' elif wx.Port == '__WXGTK__': port = 'gtk' - if 'gtk2' in wx.PortInfo: + if 'gtk2' in wx.PlatformInfo: port = 'gtk2' else: port = '???' diff --git a/etg/pickers.py b/etg/pickers.py index 0c51c2b1..6db27511 100644 --- a/etg/pickers.py +++ b/etg/pickers.py @@ -139,7 +139,7 @@ def run(): # button can't change color. So for the Mac we'll implement our own # picker using a wx.BitmapButton instead. module.addPyCode("""\ - if 'wxMac' in wx.PortInfo: + if 'wxMac' in wx.PlatformInfo: # ColourData object to be shared by all colour pickers _colourData = None diff --git a/etg/platinfo.py b/etg/platinfo.py index ad73e8d7..0c4d9e2e 100644 --- a/etg/platinfo.py +++ b/etg/platinfo.py @@ -36,6 +36,9 @@ def run(): c = module.find('wxPlatformInfo') assert isinstance(c, etgtools.ClassDef) + # to avoid conflicts with wxPython's wx.PlatformInfo + c.pyName = 'PlatformInformation' + c.find('GetEndianness').findOverload('end').ignore() c.find('GetArchName').findOverload('arch').ignore() c.find('GetOperatingSystemId').findOverload('name').ignore() @@ -47,10 +50,6 @@ def run(): c.find('GetPortIdShortName').findOverload('port').ignore() - # Make this class act a bit like the wx.PlatformInfo tuple in Classic - c.addPyMethod('__getitem__', '(self, idx)', 'return wx.PortInfo[idx]') - c.addPyMethod('__len__', '(self)', 'return len(wx.PortInfo)') - #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/src/core_ex.cpp b/src/core_ex.cpp index dff721c9..e9ecdd69 100644 --- a/src/core_ex.cpp +++ b/src/core_ex.cpp @@ -128,16 +128,18 @@ void wxPyCoreModuleInject(PyObject* moduleDict) wxInitAllImageHandlers(); + // TODO: Find some blackmagic way to deprecate wx.Platform such that it raises + // a wraning when used... Maybe a class that returns wx.Port for any __getattr__? PyDict_SetItemString(moduleDict, "Port", PyString_FromString(wxPort)); - PyDict_SetItemString(moduleDict, "Platform", PyString_FromString(wxPort)); + PyDict_SetItemString(moduleDict, "Platform", PyString_FromString(wxPort)); // Make a tuple of strings that gives more info about the platform and build. - PyObject* PortInfo = PyList_New(0); + PyObject* PlatformInfo = PyList_New(0); PyObject* obj; #define _AddInfoString(st) \ obj = PyString_FromString(st); \ - PyList_Append(PortInfo, obj); \ + PyList_Append(PlatformInfo, obj); \ Py_DECREF(obj) _AddInfoString(wxPort); @@ -178,7 +180,7 @@ void wxPyCoreModuleInject(PyObject* moduleDict) #undef _AddInfoString - PyObject* PortInfoTuple = PyList_AsTuple(PortInfo); - Py_DECREF(PortInfo); - PyDict_SetItemString(moduleDict, "PortInfo", PortInfoTuple); + PyObject* PlatformInfoTuple = PyList_AsTuple(PlatformInfo); + Py_DECREF(PlatformInfo); + PyDict_SetItemString(moduleDict, "PlatformInfo", PlatformInfoTuple); } diff --git a/src/core_ex.py b/src/core_ex.py index d385759a..df06f2cf 100644 --- a/src/core_ex.py +++ b/src/core_ex.py @@ -19,7 +19,8 @@ if 'wxEVT_NULL' in dir(): del _core else: Port = '' - PortInfo = [] + Platform = '' + PlatformInfo = [] import warnings class wxPyDeprecationWarning(DeprecationWarning): diff --git a/unittests/test_aboutdlg.py b/unittests/test_aboutdlg.py index e4e283b0..3493c375 100644 --- a/unittests/test_aboutdlg.py +++ b/unittests/test_aboutdlg.py @@ -18,7 +18,7 @@ class aboutdlg_Tests(wtc.WidgetTestCase): def test_aboutdlgNative(self): - if not 'wxMSW' in wx.PlatformInfo(): + if not 'wxMSW' in wx.PlatformInfo: info = self._makeInfo() wx.CallLater(25, self.closeDialogs) wx.adv.AboutBox(info, self.frame) diff --git a/unittests/test_dc.py b/unittests/test_dc.py index 45b661cf..ac7a03e1 100644 --- a/unittests/test_dc.py +++ b/unittests/test_dc.py @@ -95,7 +95,7 @@ class dc_Tests(wtc.WidgetTestCase): def test_NativeWinHandle(self): dc = wx.ClientDC(self.frame) - if 'wxMSW' in wx.PortInfo: + if 'wxMSW' in wx.PlatformInfo: h = dc.GetHDC() self.assertNotEqual(h, 0) else: @@ -104,7 +104,7 @@ class dc_Tests(wtc.WidgetTestCase): def test_NativeGTKHandle(self): dc = wx.ClientDC(self.frame) - if 'wxGTK' in wx.PortInfo: + if 'wxGTK' in wx.PlatformInfo: h = dc.GetGdkDrawable() self.assertNotEqual(h, 0) else: @@ -113,7 +113,7 @@ class dc_Tests(wtc.WidgetTestCase): def test_NativeMacHandle(self): dc = wx.ClientDC(self.frame) - if 'wxMac' in wx.PortInfo: + if 'wxMac' in wx.PlatformInfo: h = dc.GetCGContext() self.assertNotEqual(h, 0) else: diff --git a/unittests/test_deadobj.py b/unittests/test_deadobj.py index 71a4d4e2..99246b5b 100644 --- a/unittests/test_deadobj.py +++ b/unittests/test_deadobj.py @@ -29,7 +29,7 @@ class deadobj_Tests(wtc.WidgetTestCase): # TODO: figure out if this is a bug in wxMSW, or just an oddity of # the test environment. - if 'wxMSW' not in wx.PlatformInfo.Get(): + if 'wxMSW' not in wx.PlatformInfo: self.assertFalse(True if f else False) diff --git a/unittests/test_dialog.py b/unittests/test_dialog.py index 4de03ae8..24551724 100644 --- a/unittests/test_dialog.py +++ b/unittests/test_dialog.py @@ -11,7 +11,7 @@ class dialog_Tests(wtc.WidgetTestCase): ok = wx.Button(dlg, wx.ID_OK, pos=(10,10)) cancel = wx.Button(dlg, wx.ID_CANCEL, pos=(100,10)) - if 'wxMac' not in wx.PortInfo: + if 'wxMac' not in wx.PlatformInfo: # Something is causing a hang when running one of these tests, so # for now we'll not actually test ShowModal on Macs. # TODO: FIX THIS!! diff --git a/unittests/test_platinfo.py b/unittests/test_platinfo.py index f2f1879b..9e603eb4 100644 --- a/unittests/test_platinfo.py +++ b/unittests/test_platinfo.py @@ -7,21 +7,16 @@ import wx class platinfo_Tests(wtc.WidgetTestCase): def test_platinfo(self): - pi = wx.PlatformInfo.Get() + pi = wx.PlatformInformation.Get() pi.GetArchitecture() pi.GetOperatingSystemId() pi.GetPortId() - - def test_platinfoClassicCompatibility(self): - self.assertTrue( ('wxMac' in wx.PlatformInfo.Get()) == ('wxMac' in wx.PortInfo) ) - self.assertTrue( ('wxMSW' in wx.PlatformInfo.Get()) == ('wxMSW' in wx.PortInfo) ) - self.assertTrue( ('wxGTK' in wx.PlatformInfo.Get()) == ('wxGTK' in wx.PortInfo) ) - + def test_platinfoProperties(self): - pi = wx.PlatformInfo.Get() + pi = wx.PlatformInformation.Get() pi.ArchName pi.Architecture pi.DesktopEnvironment diff --git a/unittests/test_process.py b/unittests/test_process.py index 249f44fc..bde0dba0 100644 --- a/unittests/test_process.py +++ b/unittests/test_process.py @@ -12,7 +12,7 @@ class process_Tests(wtc.WidgetTestCase): def test_process1(self): # wx.Execute and wx.Process can only launch app bundles on OSX!! It's # a good thing we have the subprocess module that can be used instead. - if 'wxMac' not in wx.PortInfo: + if 'wxMac' not in wx.PlatformInfo: p = wx.Process.Open('%s %s' % (sys.executable, testscript)) pid = p.GetPid() @@ -22,7 +22,7 @@ class process_Tests(wtc.WidgetTestCase): def onEndProcess(evt): flag = True - if 'wxMac' not in wx.PortInfo: + if 'wxMac' not in wx.PlatformInfo: p = wx.Process(self.frame) self.frame.Bind(wx.EVT_END_PROCESS, onEndProcess) wx.Execute('%s %s' % (sys.executable, testscript), callback=p) diff --git a/unittests/wtc.py b/unittests/wtc.py index b804e75c..e3318cda 100644 --- a/unittests/wtc.py +++ b/unittests/wtc.py @@ -42,7 +42,7 @@ class WidgetTestCase(unittest.TestCase): 1/30 of second we need to wait a little to ensure that there will actually be a paint event while we are yielding. """ - if 'wxOSX' in wx.PlatformInfo(): + if 'wxOSX' in wx.PlatformInfo: wx.MilliSleep(40) # a little more than 1/30, just in case window.Update()