2007-08-12 03:32:45 +00:00
|
|
|
/****************************/
|
|
|
|
/* pyhandler.h */
|
|
|
|
/****************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#ifndef PYHANDLER_H
|
|
|
|
#define PYHANDLER_H
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
2007-08-12 03:32:45 +00:00
|
|
|
|
|
|
|
#include <Python.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
#include <wx/wxPython/wxPython.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/* Use the boost library : */
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
class PyHandler
|
|
|
|
{
|
|
|
|
typedef void (*initfunc_t )();
|
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
private:
|
|
|
|
static PyHandler* m_instance;
|
|
|
|
bool m_ModulesLoaded;
|
|
|
|
int m_current;
|
|
|
|
PyThreadState* m_mainTState;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
protected:
|
|
|
|
PyHandler();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
wxString m_appName;
|
|
|
|
void RunBaseScripts( const wxString& base );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Modules
|
|
|
|
struct ModuleRecord
|
|
|
|
{
|
|
|
|
wxString name;
|
|
|
|
std::vector< initfunc_t > registry;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
ModuleRecord( const wxString &modName ) :
|
|
|
|
name( modName )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-12 03:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector< ModuleRecord > m_ModuleRegistry;
|
|
|
|
|
|
|
|
void DoInitModules();
|
|
|
|
|
|
|
|
// Events
|
|
|
|
struct Event
|
|
|
|
{
|
|
|
|
wxString key;
|
|
|
|
std::vector< boost::python::object > functors;
|
|
|
|
|
|
|
|
Event( const wxString &strKey ) :
|
|
|
|
key( strKey )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector< Event > m_EventRegistry;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
public:
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Singletton handling:
|
|
|
|
static PyHandler* GetInstance();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
~PyHandler();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Scope params/handling:
|
|
|
|
void SetAppName( const wxString& name );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
void AddToModule( const wxString& name, initfunc_t initfunc );
|
|
|
|
int GetModuleIndex( const wxString& name ) const;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Script and direct call
|
|
|
|
void RunScripts();
|
|
|
|
bool RunScript( const wxString& name );
|
|
|
|
bool RunSimpleString( const wxString& code );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Common Informations
|
|
|
|
const char* GetVersion();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
void InitNextModule();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Event triggering
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// - C++ interface
|
|
|
|
void DeclareEvent( const wxString& key );
|
|
|
|
void TriggerEvent( const wxString& key );
|
|
|
|
void TriggerEvent( const wxString& key,
|
|
|
|
const boost::python::object& param );
|
|
|
|
int GetEventIndex( const wxString& key );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// - Py Interface
|
|
|
|
void RegisterCallback( const wxString& key,
|
|
|
|
const boost::python::object& obj );
|
|
|
|
void UnRegisterCallback( const wxString& key,
|
|
|
|
const boost::python::object& obj );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// Object conversions
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// - Py -> C++
|
|
|
|
static wxString MakeStr( const boost::python::object& objStr );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
// - C++ -> Py
|
|
|
|
static boost::python::object Convert( const wxString& wxStr );
|
2007-05-28 18:09:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
#define KICAD_PY_BIND_MODULE( mod ) PyHandler::GetInstance()->AddModule( init # mod )
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-12 03:32:45 +00:00
|
|
|
#endif //PYHANDLER_H
|