Commit f23bb59c authored by jean-pierre charras's avatar jean-pierre charras

Python scripting: make UTF8 class accessible by python scripts. Add python...

Python scripting: make UTF8 class accessible by python scripts. Add python method GetChars() to UTF8 class to get its char buffer.
See scripts/test_kicad_plugin.py for example.
parent 431ed318
......@@ -76,6 +76,10 @@ public:
{
}
~UTF8() // Needed mainly to build python wrapper
{
}
UTF8& operator=( const wxString& o );
UTF8& operator=( const std::string& o )
......@@ -144,6 +148,11 @@ public:
public:
uni_iter() // Needed only to build python wrapper, not used outside the wrapper
{
it = NULL;
}
uni_iter( const uni_iter& o )
{
it = o.it;
......
......@@ -53,6 +53,7 @@
%ignore operator <<;
%ignore operator=;
/* headers/imports that must be included in the _wrapper.cpp at top */
%{
......@@ -70,7 +71,6 @@
#include <eda_text.h>
#include <convert_from_iu.h>
#include <convert_to_biu.h>
%}
/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */
......@@ -110,7 +110,30 @@
/* std template mappings */
%template(intVector) std::vector<int>;
%template(str_utf8_Map) std::map< std::string,UTF8 >;
/* KiCad plugin handling */
%include "kicadplugins.i"
// ignore warning relative to operator = and operator ++:
#pragma SWIG nowarn=362,383
// Rename operators defined in utf8.h
%rename(utf8_to_charptr) operator char* () const;
%rename(utf8_to_wxstring) operator wxString () const;
#include <utf8.h>
%include <utf8.h>
%extend UTF8
{
const char* Cast_to_CChar() { return (self->c_str()); }
%pythoncode
{
def GetChars(self):
return self.Cast_to_CChar()
}
}
......@@ -20,8 +20,8 @@ import sys
import os
lib_path1='/tmp/lib1.pretty'
lib_path2='/tmp/lib2.pretty'
lib_path1='f:/tmp/lib1.pretty'
lib_path2='f:/tmp/lib2.pretty'
plugin = IO_MGR.PluginFind( IO_MGR.KICAD )
......@@ -65,23 +65,27 @@ plugin.FootprintSave( lib_path1, module )
# create a disparity between the library's name ("footprint"),
# and the module's internal useless name ("mine"). Module is officially named "footprint" now
# but has (module mine ...) internally:
os.rename( '/tmp/lib2.pretty/mine.kicad_mod', '/tmp/lib2.pretty/footprint.kicad_mod' )
os.rename( 'f:/tmp/lib2.pretty/mine.kicad_mod', 'f:/tmp/lib2.pretty/footprint.kicad_mod' )
footprint=plugin.FootprintLoad( lib_path2, 'footprint' )
fpid = footprint.GetFPID()
fpid.SetLibNickname( UTF8( 'mylib' ) )
name = fpid.Format().GetChars()
# Always after a FootprintLoad() the internal name should match the one used to load it.
print( "internal name should be 'footprint':", fpid.GetFootprintName() )
print( "internal name should be 'footprint':", name )
# Verify that the same plugin instance can edge trigger on a lib_path change
# for FootprintLoad()
footprint=plugin.FootprintLoad( lib_path1, 'mine' )
fpid = footprint.GetFPID()
fpid.SetLibNickname( UTF8( 'other_mylib' ) )
name = fpid.Format().GetChars()
# Always after a FootprintLoad() the internal name should match the one used to load it.
print( "internal name should be 'mine':", fpid.GetFootprintName() )
print( "internal name should be 'mine':", name )
# As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment