mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-27 06:00:07 +01:00
* Changed imports to use either absolute or explicit relative imports. Implicit relative imports are no longer allowed. * Changes to accomodate standard library classes or modues moving to other locations, or being removed entirely. * Changes related to print becoming a function, execfile being removed, u'' no longer allowed, and other syntax related issues. * Working around C APIs that have changed or simply vanished. (PyInt, PyString, PyBytes, etc.) * Dealing with text file objects using strings vs binary file objects using bytes, auto-encoding, and etc. * Replacing the use of PyCObject with PyCapsule and dealing with an apparent bug where PyCapsule objects can't be imported from submodules within a package. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
71 lines
2.2 KiB
Plaintext
71 lines
2.2 KiB
Plaintext
//--------------------------------------------------------------------------
|
|
// Name: string.sip
|
|
// Purpose: Implements a %MappedType for wxString
|
|
//
|
|
// Author: Robin Dunn
|
|
//
|
|
// Created: 9-Nov-2010
|
|
// Copyright: (c) 2011 by Total Control Software
|
|
// Licence: wxWindows license
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
// We don't want the Python user to ever need to deal directly with wxString
|
|
// at all, so it will be mapped to and from Python Unicode objects using the
|
|
// code snippets below.
|
|
// NOTE: Currently we assume that string objects are encoded in utf-8.
|
|
|
|
%MappedType wxString
|
|
{
|
|
|
|
// TODO: It is still possible to have a wx build that uses utf-8 inside
|
|
// wxString, so we should probably be checking wxUSE_UNICODE_WCHAR or
|
|
// wxUSE_UNICODE_UTF8 for this conversion.
|
|
|
|
%ConvertToTypeCode
|
|
// Code to test a PyObject for compatibility with wxString
|
|
if (!sipIsErr) {
|
|
if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy))
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
// Code to convert a compatible PyObject to a wxString
|
|
PyObject* uni = sipPy;
|
|
if (PyBytes_Check(sipPy)) {
|
|
// if it's a string object convert it to unicode first, assuming utf-8
|
|
uni = PyUnicode_FromEncodedObject(sipPy, "utf-8", "strict");
|
|
if (PyErr_Occurred()) {
|
|
*sipIsErr = 1;
|
|
return 0;
|
|
}
|
|
}
|
|
*sipCppPtr = new wxString();
|
|
size_t len = PyUnicode_GET_SIZE(uni);
|
|
if (len) {
|
|
wxPyUnicode_AsWideChar(uni, wxStringBuffer(**sipCppPtr, len), len);
|
|
}
|
|
if (PyBytes_Check(sipPy))
|
|
Py_DECREF(uni); // release the temporary Unicode object we created
|
|
return sipGetState(sipTransferObj);
|
|
%End
|
|
|
|
|
|
%ConvertFromTypeCode
|
|
// Convert a wxString to a Python Unicode object. See wxpy_api.sip
|
|
return wx2PyString(*sipCpp);
|
|
%End
|
|
};
|
|
|
|
|
|
|
|
// Used just for testing the MappedType code, it can be removed later
|
|
%ModuleCode
|
|
wxString testStringTypemap(const wxString& str)
|
|
{
|
|
wxString local = str;
|
|
return local;
|
|
}
|
|
%End
|
|
wxString testStringTypemap(const wxString& str);
|