KiCad PCB EDA Suite
PYTHON_ACTION_PLUGIN Class Reference

#include <pcbnew_action_plugins.h>

Inheritance diagram for PYTHON_ACTION_PLUGIN:
ACTION_PLUGIN

Public Member Functions

 PYTHON_ACTION_PLUGIN (PyObject *action)
 
 ~PYTHON_ACTION_PLUGIN ()
 
wxString GetCategoryName () override
 Function GetCategoryName. More...
 
wxString GetName () override
 Function GetName. More...
 
wxString GetDescription () override
 Function GetDescription. More...
 
void Run () override
 Function Run This method the the action. More...
 
void * GetObject () override
 Function GetObject This method gets the pointer to the object from where this action constructs. More...
 
void register_action ()
 Function register_action It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS singleton manager. More...
 

Public Attributes

int m_actionMenuId
 

Private Member Functions

PyObject * CallMethod (const char *aMethod, PyObject *aArglist=NULL)
 
wxString CallRetStrMethod (const char *aMethod, PyObject *aArglist=NULL)
 

Private Attributes

PyObject * m_PyAction
 

Detailed Description

Definition at line 36 of file pcbnew_action_plugins.h.

Constructor & Destructor Documentation

PYTHON_ACTION_PLUGIN::PYTHON_ACTION_PLUGIN ( PyObject *  action)

Definition at line 44 of file pcbnew_action_plugins.cpp.

References m_PyAction.

45 {
46  PyLOCK lock;
47 
48  this->m_PyAction = aAction;
49  Py_XINCREF( aAction );
50 }
PYTHON_ACTION_PLUGIN::~PYTHON_ACTION_PLUGIN ( )

Definition at line 53 of file pcbnew_action_plugins.cpp.

References m_PyAction.

54 {
55  PyLOCK lock;
56 
57  Py_XDECREF( this->m_PyAction );
58 }

Member Function Documentation

PyObject * PYTHON_ACTION_PLUGIN::CallMethod ( const char *  aMethod,
PyObject *  aArglist = NULL 
)
private

Definition at line 61 of file pcbnew_action_plugins.cpp.

References m_PyAction, and PyErrStringWithTraceback().

Referenced by CallRetStrMethod(), and Run().

62 {
63  PyLOCK lock;
64 
65  PyErr_Clear();
66  // pFunc is a new reference to the desired method
67  PyObject* pFunc = PyObject_GetAttrString( this->m_PyAction, aMethod );
68 
69  if( pFunc && PyCallable_Check( pFunc ) )
70  {
71  PyObject* result = PyObject_CallObject( pFunc, aArglist );
72 
73  if( PyErr_Occurred() )
74  {
75  wxMessageBox( PyErrStringWithTraceback(),
76  wxT( "Exception on python action plugin code" ),
77  wxICON_ERROR | wxOK );
78  }
79 
80  if( result )
81  {
82  Py_XDECREF( pFunc );
83  return result;
84  }
85  }
86  else
87  {
88  printf( "method not found, or not callable: %s\n", aMethod );
89  }
90 
91  if( pFunc )
92  {
93  Py_XDECREF( pFunc );
94  }
95 
96  return NULL;
97 }
wxString PyErrStringWithTraceback()
wxString PYTHON_ACTION_PLUGIN::CallRetStrMethod ( const char *  aMethod,
PyObject *  aArglist = NULL 
)
private

Definition at line 100 of file pcbnew_action_plugins.cpp.

References CallMethod(), and FROM_UTF8().

Referenced by GetCategoryName(), GetDescription(), and GetName().

101 {
102  wxString ret;
103  PyLOCK lock;
104 
105  PyObject* result = CallMethod( aMethod, aArglist );
106 
107  if( result )
108  {
109  const char* str_res = PyString_AsString( result );
110  ret = FROM_UTF8( str_res );
111  Py_DECREF( result );
112  }
113 
114  return ret;
115 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_ACTION_PLUGIN::GetCategoryName ( )
overridevirtual

Function GetCategoryName.

Returns
the category name of the action (to be able to group action under the same submenu)

Implements ACTION_PLUGIN.

Definition at line 118 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

119 {
120  PyLOCK lock;
121 
122  return CallRetStrMethod( "GetCategoryName" );
123 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_ACTION_PLUGIN::GetDescription ( )
overridevirtual

Function GetDescription.

Returns
a description of the action plugin

Implements ACTION_PLUGIN.

Definition at line 134 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

135 {
136  PyLOCK lock;
137 
138  return CallRetStrMethod( "GetDescription" );
139 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_ACTION_PLUGIN::GetName ( )
overridevirtual

Function GetName.

Returns
the name of the action

Implements ACTION_PLUGIN.

Definition at line 126 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

127 {
128  PyLOCK lock;
129 
130  return CallRetStrMethod( "GetName" );
131 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
void * PYTHON_ACTION_PLUGIN::GetObject ( )
overridevirtual

Function GetObject This method gets the pointer to the object from where this action constructs.

Returns
it's a void pointer, as it could be a PyObject or any other

Implements ACTION_PLUGIN.

Definition at line 150 of file pcbnew_action_plugins.cpp.

References m_PyAction.

151 {
152  return (void*) m_PyAction;
153 }
void ACTION_PLUGIN::register_action ( )
inherited

Function register_action It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS singleton manager.

Definition at line 38 of file class_action_plugin.cpp.

References ACTION_PLUGINS::register_action().

Referenced by PYTHON_ACTION_PLUGINS::register_action().

39 {
41 }
static void register_action(ACTION_PLUGIN *aAction)
Function register_action An action calls this static method when it wants to register itself into the...
void PYTHON_ACTION_PLUGIN::Run ( )
overridevirtual

Function Run This method the the action.

Implements ACTION_PLUGIN.

Definition at line 142 of file pcbnew_action_plugins.cpp.

References CallMethod().

143 {
144  PyLOCK lock;
145 
146  CallMethod( "Run" );
147 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)

Member Data Documentation

int ACTION_PLUGIN::m_actionMenuId
inherited

Definition at line 46 of file class_action_plugin.h.

PyObject* PYTHON_ACTION_PLUGIN::m_PyAction
private

The documentation for this class was generated from the following files: