Browse Source

Get Action Plugins working with Python 3, fix some unicode string errors

pull/13/head
Thomas Pointhuber 7 years ago
committed by Maciej Suminski
parent
commit
88d04f3bcb
  1. 2
      common/swig/wx_python_helpers.cpp
  2. 10
      pcbnew/swig/pcbnew_action_plugins.cpp
  3. 20
      pcbnew/swig/pcbnew_footprint_wizards.cpp
  4. 23
      pcbnew/swig/python_scripting.cpp
  5. 2
      scripting/kicadplugins.i

2
common/swig/wx_python_helpers.cpp

@ -136,7 +136,7 @@ wxString* newWxStringFromPy( PyObject* src )
return NULL;
}
#if PY_MAJOR_VERSION >= 3
else if( !PyBytes_Check( src ) )
else if( !PyUnicode_Check( src ) )
#else
else if( !PyString_Check( src ) ) // if it's not a string, str(obj)
#endif

10
pcbnew/swig/pcbnew_action_plugins.cpp

@ -108,7 +108,15 @@ wxString PYTHON_ACTION_PLUGIN::CallRetStrMethod( const char* aMethod, PyObject*
if( result )
{
#if PY_MAJOR_VERSION >= 3
const char* str_res = PyBytes_AS_STRING( result );
const char* str_res = NULL;
PyObject* temp_bytes = PyUnicode_AsEncodedString( result, "UTF-8", "strict" );
if ( temp_bytes != NULL ) {
str_res = PyBytes_AS_STRING( temp_bytes );
str_res = strdup( str_res );
Py_DECREF( temp_bytes );
} else {
wxLogMessage( "cannot encode unicode python string" );
}
#else
const char* str_res = PyString_AsString( result );
#endif

20
pcbnew/swig/pcbnew_footprint_wizards.cpp

@ -102,7 +102,15 @@ wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod( const char* aMethod, PyObjec
if( result )
{
#if PY_MAJOR_VERSION >= 3
const char* str_res = PyBytes_AS_STRING( result );
const char* str_res = NULL;
PyObject* temp_bytes = PyUnicode_AsEncodedString( result, "UTF-8", "strict" );
if ( temp_bytes != NULL ) {
str_res = PyBytes_AS_STRING( temp_bytes );
str_res = strdup( str_res );
Py_DECREF( temp_bytes );
} else {
wxLogMessage( "cannot encode unicode python string" );
}
#else
const char* str_res = PyString_AsString( result );
#endif
@ -209,7 +217,15 @@ wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName( int aPage )
if( result )
{
#if PY_MAJOR_VERSION >= 3
const char* str_res = PyBytes_AS_STRING( result );
const char* str_res = NULL;
PyObject* temp_bytes = PyUnicode_AsEncodedString( result, "UTF-8", "strict" );
if ( temp_bytes != NULL ) {
str_res = PyBytes_AS_STRING( temp_bytes );
str_res = strdup( str_res );
Py_DECREF( temp_bytes );
} else {
wxLogMessage( "cannot encode unicode python string" );
}
#else
const char* str_res = PyString_AsString( result );
#endif

23
pcbnew/swig/python_scripting.cpp

@ -249,7 +249,17 @@ static void pcbnewRunPythonMethodWithReturnedString( const char* aMethodName, wx
{
PyObject* str = PyDict_GetItemString(localDict, "result" );
#if PY_MAJOR_VERSION >= 3
const char* str_res = str ? PyBytes_AS_STRING( str ) : 0;
const char* str_res = NULL;
if(str) {
PyObject* temp_bytes = PyUnicode_AsEncodedString( str, "UTF-8", "strict" );
if ( temp_bytes != NULL ) {
str_res = PyBytes_AS_STRING( temp_bytes );
str_res = strdup( str_res );
Py_DECREF( temp_bytes );
} else {
wxLogMessage( "cannot encode unicode python string" );
}
}
#else
const char* str_res = str ? PyString_AsString( str ) : 0;
#endif
@ -404,7 +414,16 @@ wxArrayString PyArrayStringToWx( PyObject* aArrayString )
if( element )
{
#if PY_MAJOR_VERSION >= 3
ret.Add( FROM_UTF8( PyBytes_AS_STRING( element ) ), 1 );
const char* str_res = NULL;
PyObject* temp_bytes = PyUnicode_AsEncodedString( element, "UTF-8", "strict" );
if ( temp_bytes != NULL ) {
str_res = PyBytes_AS_STRING( temp_bytes );
str_res = strdup( str_res );
Py_DECREF( temp_bytes );
ret.Add( FROM_UTF8( str_res ), 1 );
} else {
wxLogMessage( "cannot encode unicode python string" );
}
#else
ret.Add( FROM_UTF8( PyString_AsString( element ) ), 1 );
#endif

2
scripting/kicadplugins.i

@ -102,7 +102,7 @@ def LoadOnePlugin(Dirname, ModuleName):
try: # If there is an error loading the script, skip it
mtime = os.path.getmtime(module_filename)
if KICAD_PLUGINS.has_key(ModuleName):
if ModuleName in KICAD_PLUGINS:
plugin = KICAD_PLUGINS[ModuleName]
if not plugin["modification_time"] == mtime:

Loading…
Cancel
Save