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.

Referenced by PYTHON_ACTION_PLUGINS::register_action().

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 Format(), 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  _( "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  wxString msg = wxString::Format(_( "Method \"%s\" not found, or not callable" ), aMethod );
89  wxMessageBox( msg, _( "Unknown Method" ), wxICON_ERROR | wxOK );
90  }
91 
92  if( pFunc )
93  {
94  Py_XDECREF( pFunc );
95  }
96 
97  return NULL;
98 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxString PyErrStringWithTraceback()
wxString PYTHON_ACTION_PLUGIN::CallRetStrMethod ( const char *  aMethod,
PyObject *  aArglist = NULL 
)
private

Definition at line 101 of file pcbnew_action_plugins.cpp.

References CallMethod(), and FROM_UTF8().

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

102 {
103  wxString ret;
104  PyLOCK lock;
105 
106  PyObject* result = CallMethod( aMethod, aArglist );
107 
108  if( result )
109  {
110  const char* str_res = PyString_AsString( result );
111  ret = FROM_UTF8( str_res );
112  Py_DECREF( result );
113  }
114 
115  return ret;
116 }
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 119 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

120 {
121  PyLOCK lock;
122 
123  return CallRetStrMethod( "GetCategoryName" );
124 }
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 135 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

Referenced by PYTHON_ACTION_PLUGINS::deregister_action().

136 {
137  PyLOCK lock;
138 
139  return CallRetStrMethod( "GetDescription" );
140 }
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 127 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

Referenced by PYTHON_ACTION_PLUGINS::deregister_action().

128 {
129  PyLOCK lock;
130 
131  return CallRetStrMethod( "GetName" );
132 }
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 151 of file pcbnew_action_plugins.cpp.

References m_PyAction.

152 {
153  return (void*) m_PyAction;
154 }
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 action_plugin.cpp.

References ACTION_PLUGINS::m_actionRunning, ACTION_PLUGINS::m_actionsList, and ACTION_PLUGINS::register_action().

Referenced by ACTION_PLUGIN::ACTION_PLUGIN(), and 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 143 of file pcbnew_action_plugins.cpp.

References CallMethod().

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

Member Data Documentation

int ACTION_PLUGIN::m_actionMenuId
inherited

Definition at line 46 of file action_plugin.h.

Referenced by ACTION_PLUGINS::GetActionByMenu().

PyObject* PYTHON_ACTION_PLUGIN::m_PyAction
private

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