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...
 
bool GetShowToolbarButton () override
 Function GetShowToolbarButton. More...
 
wxString GetIconFileName () override
 Function GetIconFileName. More...
 
wxString GetPluginPath () override
 Function GetPluginPath. 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
 
int m_actionButtonId
 
wxBitmap iconBitmap
 
bool show_on_toolbar
 

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 40 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(), GetShowToolbarButton(), 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 PyStringToWx().

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

102 {
103  wxString ret;
104  PyLOCK lock;
105 
106  PyObject* result = CallMethod( aMethod, aArglist );
107 
108  ret = PyStringToWx( result );
109  Py_XDECREF( result );
110 
111  return ret;
112 }
wxString PyStringToWx(PyObject *aString)
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 115 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

116 {
117  PyLOCK lock;
118 
119  return CallRetStrMethod( "GetCategoryName" );
120 }
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 131 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

132 {
133  PyLOCK lock;
134 
135  return CallRetStrMethod( "GetDescription" );
136 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_ACTION_PLUGIN::GetIconFileName ( )
overridevirtual

Function GetIconFileName.

Returns
a path to icon for the action plugin button

Implements ACTION_PLUGIN.

Definition at line 149 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

150 {
151  PyLOCK lock;
152 
153  return CallRetStrMethod( "GetIconFileName" );
154 }
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 123 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

124 {
125  PyLOCK lock;
126 
127  return CallRetStrMethod( "GetName" );
128 }
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 173 of file pcbnew_action_plugins.cpp.

References m_PyAction.

174 {
175  return (void*) m_PyAction;
176 }
wxString PYTHON_ACTION_PLUGIN::GetPluginPath ( )
overridevirtual

Function GetPluginPath.

Returns
a path this plugin was loaded from

Implements ACTION_PLUGIN.

Definition at line 157 of file pcbnew_action_plugins.cpp.

References CallRetStrMethod().

158 {
159  PyLOCK lock;
160 
161  return CallRetStrMethod( "GetPluginPath" );
162 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton ( )
overridevirtual

Function GetShowToolbarButton.

Returns
true if button should be shown on top toolbar

Implements ACTION_PLUGIN.

Definition at line 139 of file pcbnew_action_plugins.cpp.

References CallMethod().

140 {
141  PyLOCK lock;
142 
143  PyObject* result = CallMethod( "GetShowToolbarButton");
144 
145  return PyObject_IsTrue(result);
146 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
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 165 of file pcbnew_action_plugins.cpp.

References CallMethod().

166 {
167  PyLOCK lock;
168 
169  CallMethod( "Run" );
170 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)

Member Data Documentation

wxBitmap ACTION_PLUGIN::iconBitmap
inherited
int ACTION_PLUGIN::m_actionButtonId
inherited
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
bool ACTION_PLUGIN::show_on_toolbar
inherited

Definition at line 52 of file action_plugin.h.


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