* 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
This commit is contained in:
Robin Dunn
2012-04-24 00:15:33 +00:00
parent 053aadb224
commit 8fecc2b5f9
13 changed files with 28 additions and 53 deletions

View File

@@ -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 Font, Pen, and Brush Styles
--------------------------- ---------------------------

View File

@@ -221,13 +221,13 @@ def run():
if wx.Port == '__WXMSW__': if wx.Port == '__WXMSW__':
port = 'msw' port = 'msw'
elif wx.Port == '__WXMAC__': elif wx.Port == '__WXMAC__':
if 'wxOSX-carbon' in wx.PortInfo: if 'wxOSX-carbon' in wx.PlatformInfo:
port = 'osx-carbon' port = 'osx-carbon'
else: else:
port = 'osx-cocoa' port = 'osx-cocoa'
elif wx.Port == '__WXGTK__': elif wx.Port == '__WXGTK__':
port = 'gtk' port = 'gtk'
if 'gtk2' in wx.PortInfo: if 'gtk2' in wx.PlatformInfo:
port = 'gtk2' port = 'gtk2'
else: else:
port = '???' port = '???'

View File

@@ -139,7 +139,7 @@ def run():
# button can't change color. So for the Mac we'll implement our own # button can't change color. So for the Mac we'll implement our own
# picker using a wx.BitmapButton instead. # picker using a wx.BitmapButton instead.
module.addPyCode("""\ module.addPyCode("""\
if 'wxMac' in wx.PortInfo: if 'wxMac' in wx.PlatformInfo:
# ColourData object to be shared by all colour pickers # ColourData object to be shared by all colour pickers
_colourData = None _colourData = None

View File

@@ -36,6 +36,9 @@ def run():
c = module.find('wxPlatformInfo') c = module.find('wxPlatformInfo')
assert isinstance(c, etgtools.ClassDef) assert isinstance(c, etgtools.ClassDef)
# to avoid conflicts with wxPython's wx.PlatformInfo
c.pyName = 'PlatformInformation'
c.find('GetEndianness').findOverload('end').ignore() c.find('GetEndianness').findOverload('end').ignore()
c.find('GetArchName').findOverload('arch').ignore() c.find('GetArchName').findOverload('arch').ignore()
c.find('GetOperatingSystemId').findOverload('name').ignore() c.find('GetOperatingSystemId').findOverload('name').ignore()
@@ -47,10 +50,6 @@ def run():
c.find('GetPortIdShortName').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.doCommonTweaks(module)
tools.runGenerators(module) tools.runGenerators(module)

View File

@@ -128,16 +128,18 @@ void wxPyCoreModuleInject(PyObject* moduleDict)
wxInitAllImageHandlers(); 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, "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. // 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; PyObject* obj;
#define _AddInfoString(st) \ #define _AddInfoString(st) \
obj = PyString_FromString(st); \ obj = PyString_FromString(st); \
PyList_Append(PortInfo, obj); \ PyList_Append(PlatformInfo, obj); \
Py_DECREF(obj) Py_DECREF(obj)
_AddInfoString(wxPort); _AddInfoString(wxPort);
@@ -178,7 +180,7 @@ void wxPyCoreModuleInject(PyObject* moduleDict)
#undef _AddInfoString #undef _AddInfoString
PyObject* PortInfoTuple = PyList_AsTuple(PortInfo); PyObject* PlatformInfoTuple = PyList_AsTuple(PlatformInfo);
Py_DECREF(PortInfo); Py_DECREF(PlatformInfo);
PyDict_SetItemString(moduleDict, "PortInfo", PortInfoTuple); PyDict_SetItemString(moduleDict, "PlatformInfo", PlatformInfoTuple);
} }

View File

@@ -19,7 +19,8 @@ if 'wxEVT_NULL' in dir():
del _core del _core
else: else:
Port = '' Port = ''
PortInfo = [] Platform = ''
PlatformInfo = []
import warnings import warnings
class wxPyDeprecationWarning(DeprecationWarning): class wxPyDeprecationWarning(DeprecationWarning):

View File

@@ -18,7 +18,7 @@ class aboutdlg_Tests(wtc.WidgetTestCase):
def test_aboutdlgNative(self): def test_aboutdlgNative(self):
if not 'wxMSW' in wx.PlatformInfo(): if not 'wxMSW' in wx.PlatformInfo:
info = self._makeInfo() info = self._makeInfo()
wx.CallLater(25, self.closeDialogs) wx.CallLater(25, self.closeDialogs)
wx.adv.AboutBox(info, self.frame) wx.adv.AboutBox(info, self.frame)

View File

@@ -95,7 +95,7 @@ class dc_Tests(wtc.WidgetTestCase):
def test_NativeWinHandle(self): def test_NativeWinHandle(self):
dc = wx.ClientDC(self.frame) dc = wx.ClientDC(self.frame)
if 'wxMSW' in wx.PortInfo: if 'wxMSW' in wx.PlatformInfo:
h = dc.GetHDC() h = dc.GetHDC()
self.assertNotEqual(h, 0) self.assertNotEqual(h, 0)
else: else:
@@ -104,7 +104,7 @@ class dc_Tests(wtc.WidgetTestCase):
def test_NativeGTKHandle(self): def test_NativeGTKHandle(self):
dc = wx.ClientDC(self.frame) dc = wx.ClientDC(self.frame)
if 'wxGTK' in wx.PortInfo: if 'wxGTK' in wx.PlatformInfo:
h = dc.GetGdkDrawable() h = dc.GetGdkDrawable()
self.assertNotEqual(h, 0) self.assertNotEqual(h, 0)
else: else:
@@ -113,7 +113,7 @@ class dc_Tests(wtc.WidgetTestCase):
def test_NativeMacHandle(self): def test_NativeMacHandle(self):
dc = wx.ClientDC(self.frame) dc = wx.ClientDC(self.frame)
if 'wxMac' in wx.PortInfo: if 'wxMac' in wx.PlatformInfo:
h = dc.GetCGContext() h = dc.GetCGContext()
self.assertNotEqual(h, 0) self.assertNotEqual(h, 0)
else: else:

View File

@@ -29,7 +29,7 @@ class deadobj_Tests(wtc.WidgetTestCase):
# TODO: figure out if this is a bug in wxMSW, or just an oddity of # TODO: figure out if this is a bug in wxMSW, or just an oddity of
# the test environment. # the test environment.
if 'wxMSW' not in wx.PlatformInfo.Get(): if 'wxMSW' not in wx.PlatformInfo:
self.assertFalse(True if f else False) self.assertFalse(True if f else False)

View File

@@ -11,7 +11,7 @@ class dialog_Tests(wtc.WidgetTestCase):
ok = wx.Button(dlg, wx.ID_OK, pos=(10,10)) ok = wx.Button(dlg, wx.ID_OK, pos=(10,10))
cancel = wx.Button(dlg, wx.ID_CANCEL, pos=(100,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 # Something is causing a hang when running one of these tests, so
# for now we'll not actually test ShowModal on Macs. # for now we'll not actually test ShowModal on Macs.
# TODO: FIX THIS!! # TODO: FIX THIS!!

View File

@@ -7,21 +7,16 @@ import wx
class platinfo_Tests(wtc.WidgetTestCase): class platinfo_Tests(wtc.WidgetTestCase):
def test_platinfo(self): def test_platinfo(self):
pi = wx.PlatformInfo.Get() pi = wx.PlatformInformation.Get()
pi.GetArchitecture() pi.GetArchitecture()
pi.GetOperatingSystemId() pi.GetOperatingSystemId()
pi.GetPortId() 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): def test_platinfoProperties(self):
pi = wx.PlatformInfo.Get() pi = wx.PlatformInformation.Get()
pi.ArchName pi.ArchName
pi.Architecture pi.Architecture
pi.DesktopEnvironment pi.DesktopEnvironment

View File

@@ -12,7 +12,7 @@ class process_Tests(wtc.WidgetTestCase):
def test_process1(self): def test_process1(self):
# wx.Execute and wx.Process can only launch app bundles on OSX!! It's # 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. # 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)) p = wx.Process.Open('%s %s' % (sys.executable, testscript))
pid = p.GetPid() pid = p.GetPid()
@@ -22,7 +22,7 @@ class process_Tests(wtc.WidgetTestCase):
def onEndProcess(evt): def onEndProcess(evt):
flag = True flag = True
if 'wxMac' not in wx.PortInfo: if 'wxMac' not in wx.PlatformInfo:
p = wx.Process(self.frame) p = wx.Process(self.frame)
self.frame.Bind(wx.EVT_END_PROCESS, onEndProcess) self.frame.Bind(wx.EVT_END_PROCESS, onEndProcess)
wx.Execute('%s %s' % (sys.executable, testscript), callback=p) wx.Execute('%s %s' % (sys.executable, testscript), callback=p)

View File

@@ -42,7 +42,7 @@ class WidgetTestCase(unittest.TestCase):
1/30 of second we need to wait a little to ensure that there will 1/30 of second we need to wait a little to ensure that there will
actually be a paint event while we are yielding. 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 wx.MilliSleep(40) # a little more than 1/30, just in case
window.Update() window.Update()