From 54520f7a3a02304388384d75a9dedb22b3fe488b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 24 Oct 2011 18:27:37 +0000 Subject: [PATCH] Make the new wx.PlatformInfo able to act like a seqeunce containing the same strings as the Classic wx.PlatformInfo. Add unit tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69518 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/MigrationGuide.txt | 18 +++++-- etg/platinfo.py | 23 ++++++-- unittests/test_platinfo.py | 108 +++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 unittests/test_platinfo.py diff --git a/docs/MigrationGuide.txt b/docs/MigrationGuide.txt index 8f4a54e2..445df338 100644 --- a/docs/MigrationGuide.txt +++ b/docs/MigrationGuide.txt @@ -111,15 +111,25 @@ your encoding to Unicode before passing the text to the wx API. -wx.Platform, wx.PlatformInfo, wx.USE_UNICODE and wx.__WXDEBUG__ ---------------------------------------------------------------- +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. +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(): + ... -In related news, wx.USE_UNICODE and wx.__WXDEBUG__ have been removed. diff --git a/etg/platinfo.py b/etg/platinfo.py index 431e6b3d..bafd7845 100644 --- a/etg/platinfo.py +++ b/etg/platinfo.py @@ -17,7 +17,9 @@ DOCSTRING = "" # The classes and/or the basename of the Doxygen XML files to be processed by # this script. -ITEMS = [ 'wxPlatformInfo' ] +ITEMS = [ 'wxPlatformInfo', + 'wxLinuxDistributionInfo', + ] #--------------------------------------------------------------------------- @@ -30,17 +32,28 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. - + c = module.find('wxPlatformInfo') assert isinstance(c, etgtools.ClassDef) - c.find('wxPlatformInfo').findOverload('()').ignore() - c.find('GetLinuxDistributionInfo').ignore() - c.find('SetLinuxDistributionInfo').ignore() + c.find('GetEndianness').findOverload('end').ignore() + c.find('GetArchName').findOverload('arch').ignore() + c.find('GetOperatingSystemId').findOverload('name').ignore() + c.find('GetPortId').findOverload('portname').ignore() + c.find('GetEndiannessName').findOverload('end').ignore() + c.find('GetOperatingSystemIdName').findOverload('os').ignore() + c.find('GetOperatingSystemFamilyName').findOverload('os').ignore() + c.find('GetPortIdName').findOverload('port').ignore() + 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.addAutoProperties(module) tools.runGenerators(module) diff --git a/unittests/test_platinfo.py b/unittests/test_platinfo.py new file mode 100644 index 00000000..a286b956 --- /dev/null +++ b/unittests/test_platinfo.py @@ -0,0 +1,108 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class platinfo_Tests(wtc.WidgetTestCase): + + def test_platinfo(self): + pi = wx.PlatformInfo.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.ArchName + pi.Architecture + pi.DesktopEnvironment + pi.Endianness + pi.EndiannessName + pi.LinuxDistributionInfo + pi.OSMajorVersion + pi.OSMinorVersion + pi.OperatingSystemDescription + pi.OperatingSystemFamilyName + pi.OperatingSystemId + pi.OperatingSystemIdName + pi.PortId + pi.PortIdName + pi.PortIdShortName + pi.ToolkitMajorVersion + pi.ToolkitMinorVersion + + + def test_platinfoFlags(self): + wx.OS_UNKNOWN + wx.OS_MAC_OS + wx.OS_MAC_OSX_DARWIN + wx.OS_MAC + wx.OS_WINDOWS_9X + wx.OS_WINDOWS_NT + wx.OS_WINDOWS_MICRO + wx.OS_WINDOWS_CE + wx.OS_WINDOWS + wx.OS_UNIX_LINUX + wx.OS_UNIX_FREEBSD + wx.OS_UNIX_OPENBSD + wx.OS_UNIX_NETBSD + wx.OS_UNIX_SOLARIS + wx.OS_UNIX_AIX + wx.OS_UNIX_HPUX + wx.OS_UNIX + wx.OS_DOS + wx.OS_OS2 + + wx.PORT_UNKNOWN + wx.PORT_BASE + wx.PORT_MSW + wx.PORT_MOTIF + wx.PORT_GTK + wx.PORT_MGL + wx.PORT_X11 + wx.PORT_OS2 + wx.PORT_MAC + wx.PORT_COCOA + wx.PORT_WINCE + wx.PORT_PALMOS + wx.PORT_DFB + + wx.PORT_UNKNOWN + wx.PORT_BASE + wx.PORT_MSW + wx.PORT_MOTIF + wx.PORT_GTK + wx.PORT_MGL + wx.PORT_X11 + wx.PORT_OS2 + wx.PORT_MAC + wx.PORT_COCOA + wx.PORT_WINCE + wx.PORT_PALMOS + wx.PORT_DFB + + wx.ARCH_INVALID + wx.ARCH_32 + wx.ARCH_64 + wx.ARCH_MAX + + wx.ENDIAN_INVALID + wx.ENDIAN_BIG + wx.ENDIAN_LITTLE + wx.ENDIAN_PDP + wx.ENDIAN_MAX + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main()