Commit 08af5772 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

code cleanup and comments

parent db427cb2
...@@ -46,18 +46,6 @@ void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard) ...@@ -46,18 +46,6 @@ void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard)
m_FootprintWizards.push_back(aWizard); m_FootprintWizards.push_back(aWizard);
printf("Registered footprint wizard '%s'\n",(const char*)name.mb_str() ); printf("Registered footprint wizard '%s'\n",(const char*)name.mb_str() );
#if 0
/* just to test if it works correctly */
int pages = fw->GetNumParameterPages();
printf(" %d pages\n",pages);
for (int n=0; n<pages; n++)
{
printf(" page %d->'%s'\n",n,
(const char*)fw->GetParameterPageName(n).mb_str());
}
#endif
} }
......
...@@ -16,16 +16,80 @@ class FOOTPRINT_WIZARD ...@@ -16,16 +16,80 @@ class FOOTPRINT_WIZARD
public: public:
FOOTPRINT_WIZARD() {} FOOTPRINT_WIZARD() {}
~FOOTPRINT_WIZARD() {} ~FOOTPRINT_WIZARD() {}
/**
* Function GetName
* @return the name of the wizard
*/
virtual wxString GetName()=0; virtual wxString GetName()=0;
/**
* Function GetImage
* @return an svg image of the wizard to be rendered
*/
virtual wxString GetImage()=0; virtual wxString GetImage()=0;
/**
* Function GetDescription
* @return a description of the footprint wizard
*/
virtual wxString GetDescription()=0; virtual wxString GetDescription()=0;
/**
* Function GetNumParameterPages
* @return the number of parameter pages that this wizard will show to the user
*/
virtual int GetNumParameterPages()=0; virtual int GetNumParameterPages()=0;
/**
* Function GetParameterPageName
* @param aPage is the page we want the name of
* @return a string with the page name
*/
virtual wxString GetParameterPageName(int aPage)=0; virtual wxString GetParameterPageName(int aPage)=0;
/**
* Function GetParameterNames
* @param aPage is the page we want the parameter names of
* @return an array string with the parameter names on a certain page
*/
virtual wxArrayString GetParameterNames(int aPage)=0; virtual wxArrayString GetParameterNames(int aPage)=0;
/**
* Function GetParameterValues
* @param aPage is the page we want the parameter values of
* @return an array of parameter values
*/
virtual wxArrayString GetParameterValues(int aPage)=0; virtual wxArrayString GetParameterValues(int aPage)=0;
/**
* Function GetParameterErrors
* @param aPAge is the page we want to know the errors of
* @return an array of errors (if any) for the parameters, empty strings for OK parameters
*/
virtual wxArrayString GetParameterErrors(int aPage)=0; virtual wxArrayString GetParameterErrors(int aPage)=0;
/**
* Function SetParameterValues
* @param aPage is the page we want to set the parameters in
* @param aValues are the values we want to set into the parameters
* @return an array of parameter values
*/
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0; virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
/**
* Function GetModule
* This method builds the module itself and returns it to the caller function
* @return PCB module built from the parameters given to the class
*/
virtual MODULE *GetModule()=0; virtual MODULE *GetModule()=0;
/**
* Function register_wizard
* It's the standard method of a "FOOTPRINT_WIZARD" to register itself into
* the FOOTPRINT_WIZARDS singleton manager
*
*/
void register_wizard(); void register_wizard();
}; };
...@@ -37,9 +101,35 @@ private: ...@@ -37,9 +101,35 @@ private:
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards; static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
public: public:
/**
* Function register_wizard
* A footprint wizard calls this static method when it wants to register itself
* into the system wizards
*
* @param aWizard is the footprint wizard to be registered
*
*/
static void register_wizard(FOOTPRINT_WIZARD *wizard); static void register_wizard(FOOTPRINT_WIZARD *wizard);
/**
* Function GetWizard
* @return a wizard object by it's name or NULL if it isn't available.
*
*/
static FOOTPRINT_WIZARD* GetWizard(wxString aName); static FOOTPRINT_WIZARD* GetWizard(wxString aName);
/**
* Function GetWizard
* @return a wizard object by it's number or NULL if it isn't available.
*
*/
static FOOTPRINT_WIZARD* GetWizard(int aIndex); static FOOTPRINT_WIZARD* GetWizard(int aIndex);
/**
* Function GetSize
* @return the number of wizards available into the system
*/
static int GetSize(); static int GetSize();
}; };
......
/** /**
* @file footprint wizard.cpp * @file footprint_wizard.cpp
*/ */
#include <fctsys.h> #include <fctsys.h>
...@@ -49,12 +49,18 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -49,12 +49,18 @@ void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event )
} }
} }
/* Function OnLeftClick
* Captures a left click event in the dialog
*
*/
void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) void FOOTPRINT_WIZARD_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{ {
} }
/* Function OnRightClick
* Captures a right click event in the dialog
*
*/
bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) bool FOOTPRINT_WIZARD_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{ {
return true; return true;
...@@ -163,6 +169,7 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event ) ...@@ -163,6 +169,7 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
* Function RedrawActiveWindow * Function RedrawActiveWindow
* Display the current selected component. * Display the current selected component.
* If the component is an alias, the ROOT component is displayed * If the component is an alias, the ROOT component is displayed
*
*/ */
void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) void FOOTPRINT_WIZARD_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{ {
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 Miguel Angel Ajo Pelayo <miguelangel@nbee.es>
* Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
...@@ -99,7 +100,10 @@ static wxAcceleratorEntry accels[] = ...@@ -99,7 +100,10 @@ static wxAcceleratorEntry accels[] =
#define EXTRA_BORDER_SIZE 2 #define EXTRA_BORDER_SIZE 2
/* Function FOOTPRINT_WIZARD_FRAME
* it's the constructor for the footprint wizard frame, it creates everything inside
*
*/
FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* semaphore ) : FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* semaphore ) :
PCB_BASE_FRAME( parent, MODULE_VIEWER_FRAME, _( "Footprint Wizard" ), PCB_BASE_FRAME( parent, MODULE_VIEWER_FRAME, _( "Footprint Wizard" ),
wxDefaultPosition, wxDefaultSize ) wxDefaultPosition, wxDefaultSize )
...@@ -259,6 +263,10 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME() ...@@ -259,6 +263,10 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
} }
/* Function OnCloseWindow
* Handles the close event, saving settings an destroying or releasing a semaphore from caller
*
*/
void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event ) void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
SaveSettings(); SaveSettings();
...@@ -277,6 +285,9 @@ void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -277,6 +285,9 @@ void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event )
} }
/* Function OnSashDrag
* handles the horizontal separator (sash) drag, updating the pagelist or parameter list
*/
void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event ) void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
{ {
if( event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE ) if( event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE )
...@@ -309,6 +320,10 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event ) ...@@ -309,6 +320,10 @@ void FOOTPRINT_WIZARD_FRAME::OnSashDrag( wxSashEvent& event )
} }
/* Function OnSize
* It handles a dialog resize event, asking for an update
*
*/
void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv ) void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
{ {
if( m_auimgr.GetManagedWindow() ) if( m_auimgr.GetManagedWindow() )
...@@ -317,14 +332,20 @@ void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv ) ...@@ -317,14 +332,20 @@ void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
SizeEv.Skip(); SizeEv.Skip();
} }
/* Function OnSetRelativeOffset
* Updates the cursor position and the status bar
*
*/
void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event ) void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
{ {
GetScreen()->m_O_Curseur = GetScreen()->GetCrossHairPosition(); GetScreen()->m_O_Curseur = GetScreen()->GetCrossHairPosition();
UpdateStatusBar(); UpdateStatusBar();
} }
/* Function ReCreatePageList
* It recreates the list of pages for a new loaded wizard
*
*/
void FOOTPRINT_WIZARD_FRAME::ReCreatePageList() void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
{ {
if( m_PageList == NULL ) if( m_PageList == NULL )
...@@ -349,6 +370,10 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList() ...@@ -349,6 +370,10 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
m_canvas->Refresh(); m_canvas->Refresh();
} }
/* Function ReCreateParameterList
* It creates the parameter grid for a certain wizard page of the current wizard
*
*/
void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList() void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
{ {
......
* Implement iterator for NETCLASSES (NETCLASS) see class_netclass.h * finish wizard implementation
* cleanup
* Saving modules to library (in librairi.cpp) * better build script helpers
see:
- void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewModulesOnly )
- bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibName,
MODULE* aModule,
bool aOverwrite,
bool aDisplayDialog )
What do we do about this?, ask Dick, these functions should be transplanted
to kicad plugin?
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewModulesOnly )
...@@ -40,40 +40,40 @@ ...@@ -40,40 +40,40 @@
def FromMM(iu): def FromMM(iu):
if type(iu) in [int,float]: if type(iu) in [int,float]:
return int(iu / 0.00254) return iu / 0.00254
elif type(iu) in [wxPoint,wxSize]: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(FromMM,iu)) return tuple(map(FromMM,iu))
def ToMils(iu): def ToMils(iu):
if type(iu) in [int,float]: if type(iu) in [int,float]:
return int(iu / 10.0) return iu / 10.0
elif type(iu) in [wxPoint,wxSize]: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMils,iu)) return tuple(map(ToMils,iu))
def FromMils(iu): def FromMils(iu):
if type(iu) in [int,float]: if type(iu) in [int,float]:
return int(iu*10.0) return iu*10.0
elif type(iu) in [wxPoint,wxSize]: elif type(iu) in [wxPoint,wxSize]:
return tuple(map(FromMils,iu)) return tuple(map(FromMils,iu))
def wxSizeMM(mmx,mmy): return wxSize(FromMM(mmx),FromMM(mmy)) def SizeMM(mmx,mmy): return wxSize(FromMM(mmx),FromMM(mmy))
def wxSizeMils(mmx,mmy): return wxSize(FromMils(mmx),FromMils(mmy)) def SizeMils(mmx,mmy): return wxSize(FromMils(mmx),FromMils(mmy))
def wxPointMM(mmx,mmy): return wxPoint(FromMM(mmx),FromMM(mmy)) def PointMM(mmx,mmy): return wxPoint(FromMM(mmx),FromMM(mmy))
def wxPointMils(mmx,mmy): return wxPoint(FromMils(mmx),FromMils(mmy)) def PointMils(mmx,mmy): return wxPoint(FromMils(mmx),FromMils(mmy))
def wxRectMM(x,y,wx,wy): def RectMM(x,y,wx,wy):
x = int(FromMM(x)) x = int(FromMM(x))
y = int(FromMM(y)) y = int(FromMM(y))
wx = int(FromMM(wx)) wx = int(FromMM(wx))
wy = int (FromMM(wy)) wy = int (FromMM(wy))
return wxRect(x,y,wx,wy) return wxRect(x,y,wx,wy)
def wxRectMils(x,y,wx,wy): def RectMils(x,y,wx,wy):
x = int(FromMils(x)) x = int(FromMils(x))
y = int(FromMils(y)) y = int(FromMils(y))
wx = int(FromMils(wx)) wx = int(FromMils(wx))
wy = int (FromMils(wy)) wy = int (FromMils(wy))
return wxRect(x,y,wx,wy) return wxRect(x,y,wx,wy)
} }
\ No newline at end of file
...@@ -28,79 +28,104 @@ ...@@ -28,79 +28,104 @@
*/ */
#include <python_scripting.h> #include <python_scripting.h>
#include <stdlib.h>
#include <string.h>
/* init functions defined by swig */ /* init functions defined by swig */
extern "C" void init_kicad(void); extern "C" void init_kicad( void );
extern "C" void init_pcbnew(void);
extern "C" void init_pcbnew( void );
/* python inittab that links module names to module init functions #define EXTRA_PYTHON_MODULES 2 // this is the number of python
// modules that we want to add into the list
/* python inittab that links module names to module init functions
* we will rebuild it to include the original python modules plus * we will rebuild it to include the original python modules plus
* our own ones * our own ones
*/ */
struct _inittab SwigImportInittab[1000]; struct _inittab *SwigImportInittab;
static int SwigNumModules = 0; static int SwigNumModules = 0;
/* Add a name + initfuction to our SwigImportInittab */ /* Add a name + initfuction to our SwigImportInittab */
static void swigAddModule(const char *name, void (*initfunc)()) static void swigAddModule( const char* name, void (* initfunc)() )
{ {
SwigImportInittab[SwigNumModules].name = (char *)name; SwigImportInittab[SwigNumModules].name = (char*) name;
SwigImportInittab[SwigNumModules].initfunc = initfunc; SwigImportInittab[SwigNumModules].initfunc = initfunc;
SwigNumModules++; SwigNumModules++;
SwigImportInittab[SwigNumModules].name = (char *) 0; SwigImportInittab[SwigNumModules].name = (char*) 0;
SwigImportInittab[SwigNumModules].initfunc = 0; SwigImportInittab[SwigNumModules].initfunc = 0;
} }
/* Add the builting python modules */ /* Add the builting python modules */
static void swigAddBuiltin() static void swigAddBuiltin()
{ {
int i = 0; int i = 0;
while (PyImport_Inittab[i].name) {
swigAddModule(PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc);
i++;
}
while( PyImport_Inittab[i].name )
{
i++;
}
SwigImportInittab = (struct _inittab*) malloc(
sizeof(struct _inittab)*(i+EXTRA_PYTHON_MODULES));
while( PyImport_Inittab[i].name )
{
swigAddModule( PyImport_Inittab[i].name, PyImport_Inittab[i].initfunc );
i++;
}
} }
/* Function swigAddModules
* adds the internal modules we offer to the python scripting, so they will be
* available to the scripts we run.
*
*/
static void swigAddModules() static void swigAddModules()
{ {
swigAddModule("_pcbnew",init_pcbnew); swigAddModule( "_pcbnew", init_pcbnew );
// finally it seems better to include all in just one module // finally it seems better to include all in just one module
// but in case we needed to include any other modules, // but in case we needed to include any other modules,
// it must be done like this: // it must be done like this:
// swigAddModule("_kicad",init_kicad); // swigAddModule("_kicad",init_kicad);
} }
/* Function swigSwitchPythonBuiltin
* switches python module table to our built one .
*
*/
static void swigSwitchPythonBuiltin() static void swigSwitchPythonBuiltin()
{ {
PyImport_Inittab = SwigImportInittab; PyImport_Inittab = SwigImportInittab;
} }
/* Function pcbnewInitPythonScripting
* Initializes all the python environment and publish our interface inside it
*
*/
void pcbnewInitPythonScripting() void pcbnewInitPythonScripting()
{ {
swigAddBuiltin(); swigAddBuiltin(); // add builtin functions
swigAddModules(); swigAddModules(); // add our own modules
swigSwitchPythonBuiltin(); swigSwitchPythonBuiltin(); // switch the python builtin modules to our new list
Py_Initialize();
/* setup the scripting path, we may need to add the installation path
of kicad here */
PyRun_SimpleString("import sys\n" Py_Initialize(); // call the python library to get it initialized
"sys.path.append(\".\")\n"
"import pcbnew\n"
"pcbnew.LoadPlugins()"
);
// load pcbnew inside python, and load all the user plugins, TODO: add system wide plugins
PyRun_SimpleString( "import sys\n"
"sys.path.append(\".\")\n"
"import pcbnew\n"
"pcbnew.LoadPlugins()"
);
} }
\ No newline at end of file
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
#include <Python.h> #include <Python.h>
void pcbnewInitPythonScripting(void); /* Function pcbnewInitPythonScripting
* Initializes the Python engine inside pcbnew
*/
void pcbnewInitPythonScripting( void );
#endif #endif
...@@ -33,141 +33,157 @@ ...@@ -33,141 +33,157 @@
#include <wx/arrstr.h> #include <wx/arrstr.h>
#define WX_DEFAULTENCODING_SIZE 64 #define WX_DEFAULTENCODING_SIZE 64
static char wxPythonEncoding[WX_DEFAULTENCODING_SIZE] = "ascii"; static char wxPythonEncoding[WX_DEFAULTENCODING_SIZE] = "ascii";
PyObject* wxArrayString2PyList(const wxArrayString& lst) PyObject* wxArrayString2PyList( const wxArrayString& lst )
{ {
PyObject* list = PyList_New(0); PyObject* list = PyList_New( 0 );
for (size_t i=0; i < lst.GetCount(); i++) {
for( size_t i = 0; i < lst.GetCount(); i++ )
{
#if wxUSE_UNICODE #if wxUSE_UNICODE
PyObject* pyStr = PyUnicode_FromWideChar(lst[i].c_str(), PyObject* pyStr = PyUnicode_FromWideChar( lst[i].c_str(),
lst[i].Len() lst[i].Len()
); );
#else #else
PyObject* pyStr = PyString_FromStringAndSize(lst[i].c_str(), PyObject* pyStr = PyString_FromStringAndSize( lst[i].c_str(),
lst[i].Len() lst[i].Len()
); );
#endif #endif
PyList_Append(list, pyStr); PyList_Append( list, pyStr );
Py_DECREF(pyStr); Py_DECREF( pyStr );
} }
return list; return list;
} }
wxString* newWxStringFromPy( PyObject* src )
{
bool must_unref_str = false;
wxString* newWxStringFromPy(PyObject* src) { wxString* result = NULL;
PyObject* obj = src;
bool must_unref_str=false;
wxString* result = NULL;
PyObject *obj=src;
#if wxUSE_UNICODE #if wxUSE_UNICODE
bool must_unref_obj=false; bool must_unref_obj = false;
// Unicode string to python unicode string // Unicode string to python unicode string
PyObject* uni_str = src; PyObject* uni_str = src;
// if not an str or unicode, try to str(src) // if not an str or unicode, try to str(src)
if (!PyString_Check(src) && !PyUnicode_Check(src)) if( !PyString_Check( src ) && !PyUnicode_Check( src ) )
{ {
obj = PyObject_Str(src); obj = PyObject_Str( src );
must_unref_obj = true; must_unref_obj = true;
if (PyErr_Occurred()) return NULL;
if( PyErr_Occurred() )
return NULL;
} }
if (PyString_Check(obj)) if( PyString_Check( obj ) )
{ {
uni_str = PyUnicode_FromEncodedObject(obj, wxPythonEncoding, "strict"); uni_str = PyUnicode_FromEncodedObject( obj, wxPythonEncoding, "strict" );
must_unref_str = true; must_unref_str = true;
if (PyErr_Occurred()) return NULL;
if( PyErr_Occurred() )
return NULL;
} }
result = new wxString(); result = new wxString();
size_t len = PyUnicode_GET_SIZE(uni_str); size_t len = PyUnicode_GET_SIZE( uni_str );
if (len)
if( len )
{ {
PyUnicode_AsWideChar((PyUnicodeObject*)uni_str, PyUnicode_AsWideChar( (PyUnicodeObject*) uni_str,
wxStringBuffer(*result, len),len); wxStringBuffer( *result, len ), len );
} }
if (must_unref_str) Py_DECREF(uni_str); if( must_unref_str )
if (must_unref_obj) Py_DECREF(obj); Py_DECREF( uni_str );
if( must_unref_obj )
Py_DECREF( obj );
#else #else
// normal string (or object) to normal python string // normal string (or object) to normal python string
PyObject* str = src; PyObject* str = src;
if (PyUnicode_Check(src)) // if it's unicode convert to normal string if( PyUnicode_Check( src ) ) // if it's unicode convert to normal string
{ {
str = PyUnicode_AsEncodedString(src, wxPythonEncoding, "strict"); str = PyUnicode_AsEncodedString( src, wxPythonEncoding, "strict" );
if (PyErr_Occurred()) return NULL;
if( PyErr_Occurred() )
return NULL;
} }
else if (!PyString_Check(src)) // if it's not a string, str(obj) else if( !PyString_Check( src ) ) // if it's not a string, str(obj)
{ {
str = PyObject_Str(src); str = PyObject_Str( src );
must_unref_str = true; must_unref_str = true;
if (PyErr_Occurred()) return NULL;
if( PyErr_Occurred() )
return NULL;
} }
// get the string pointer and size // get the string pointer and size
char* str_ptr; char* str_ptr;
Py_ssize_t str_size; Py_ssize_t str_size;
PyString_AsStringAndSize(str, &str_ptr, &str_size); PyString_AsStringAndSize( str, &str_ptr, &str_size );
// build the wxString from our pointer / size // build the wxString from our pointer / size
result = new wxString(str_ptr, str_size); result = new wxString( str_ptr, str_size );
if (must_unref_str) Py_DECREF(str); if( must_unref_str )
#endif Py_DECREF( str );
#endif
return result; return result;
} }
wxString Py2wxString(PyObject* src) wxString Py2wxString( PyObject* src )
{ {
wxString result; wxString result;
wxString* resPtr = newWxStringFromPy(src); wxString* resPtr = newWxStringFromPy( src );
// In case of exception clear it and return an empty string // In case of exception clear it and return an empty string
if (resPtr==NULL) if( resPtr==NULL )
{ {
PyErr_Clear(); PyErr_Clear();
return wxEmptyString; return wxEmptyString;
} }
result = *resPtr; result = *resPtr;
delete resPtr; delete resPtr;
return result; return result;
} }
PyObject* wx2PyString(const wxString& src) PyObject* wx2PyString( const wxString& src )
{ {
PyObject* str; PyObject* str;
#if wxUSE_UNICODE #if wxUSE_UNICODE
str = PyUnicode_FromWideChar(src.c_str(), src.Len()); str = PyUnicode_FromWideChar( src.c_str(), src.Len() );
#else #else
str = PyString_FromStringAndSize(src.c_str(), src.Len()); str = PyString_FromStringAndSize( src.c_str(), src.Len() );
#endif #endif
return str; return str;
} }
void wxSetDefaultPyEncoding( const char* encoding )
void wxSetDefaultPyEncoding(const char* encoding)
{ {
strncpy(wxPythonEncoding, encoding, WX_DEFAULTENCODING_SIZE); strncpy( wxPythonEncoding, encoding, WX_DEFAULTENCODING_SIZE );
} }
const char* wxGetDefaultPyEncoding() const char* wxGetDefaultPyEncoding()
{ {
return wxPythonEncoding; return wxPythonEncoding;
} }
...@@ -7,14 +7,12 @@ ...@@ -7,14 +7,12 @@
#include <wx/arrstr.h> #include <wx/arrstr.h>
PyObject* wxArrayString2PyList( const wxArrayString& lst );
wxString* newWxStringFromPy( PyObject* source );
wxString Py2wxString( PyObject* source );
PyObject* wx2PyString( const wxString& src );
void wxSetDefaultPyEncoding( const char* encoding );
PyObject* wxArrayString2PyList(const wxArrayString& lst);
wxString* newWxStringFromPy(PyObject* source);
wxString Py2wxString(PyObject* source);
PyObject* wx2PyString(const wxString& src);
void wxSetDefaultPyEncoding(const char* encoding);
const char* wxGetDefaultPyEncoding(); const char* wxGetDefaultPyEncoding();
#endif #endif
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