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::PYTHON_ACTION_PLUGIN ( PyObject *  action)

Definition at line 35 of file pcbnew_action_plugins.cpp.

36 {
37  PyLOCK lock;
38 
39  this->m_PyAction = aAction;
40  Py_XINCREF( aAction );
41 }

References m_PyAction.

◆ ~PYTHON_ACTION_PLUGIN()

PYTHON_ACTION_PLUGIN::~PYTHON_ACTION_PLUGIN ( )

Definition at line 44 of file pcbnew_action_plugins.cpp.

45 {
46  PyLOCK lock;
47 
48  Py_XDECREF( this->m_PyAction );
49 }

References m_PyAction.

Member Function Documentation

◆ CallMethod()

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

Definition at line 52 of file pcbnew_action_plugins.cpp.

53 {
54  PyLOCK lock;
55 
56  PyErr_Clear();
57  // pFunc is a new reference to the desired method
58  PyObject* pFunc = PyObject_GetAttrString( this->m_PyAction, aMethod );
59 
60  if( pFunc && PyCallable_Check( pFunc ) )
61  {
62  PyObject* result = PyObject_CallObject( pFunc, aArglist );
63 
64  if( PyErr_Occurred() )
65  {
66  wxMessageBox( PyErrStringWithTraceback(),
67  _( "Exception on python action plugin code" ),
68  wxICON_ERROR | wxOK );
69  }
70 
71  if( result )
72  {
73  Py_XDECREF( pFunc );
74  return result;
75  }
76  }
77  else
78  {
79  wxString msg = wxString::Format( _( "Method \"%s\" not found, or not callable" ), aMethod );
80  wxMessageBox( msg, _( "Unknown Method" ), wxICON_ERROR | wxOK );
81  }
82 
83  if( pFunc )
84  {
85  Py_XDECREF( pFunc );
86  }
87 
88  return NULL;
89 }
#define NULL
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:201
#define _(s)
Definition: 3d_actions.cpp:33
wxString PyErrStringWithTraceback()

References _, Format(), m_PyAction, NULL, and PyErrStringWithTraceback().

Referenced by CallRetStrMethod(), GetShowToolbarButton(), and Run().

◆ CallRetStrMethod()

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

Definition at line 92 of file pcbnew_action_plugins.cpp.

93 {
94  wxString ret;
95  PyLOCK lock;
96 
97  PyObject* result = CallMethod( aMethod, aArglist );
98 
99  ret = PyStringToWx( result );
100  Py_XDECREF( result );
101 
102  return ret;
103 }
wxString PyStringToWx(PyObject *aString)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallMethod(), and PyStringToWx().

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

◆ GetCategoryName()

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 106 of file pcbnew_action_plugins.cpp.

107 {
108  PyLOCK lock;
109 
110  return CallRetStrMethod( "GetCategoryName" );
111 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallRetStrMethod().

◆ GetDescription()

wxString PYTHON_ACTION_PLUGIN::GetDescription ( )
overridevirtual

Function GetDescription.

Returns
a description of the action plugin

Implements ACTION_PLUGIN.

Definition at line 122 of file pcbnew_action_plugins.cpp.

123 {
124  PyLOCK lock;
125 
126  return CallRetStrMethod( "GetDescription" );
127 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallRetStrMethod().

◆ GetIconFileName()

wxString PYTHON_ACTION_PLUGIN::GetIconFileName ( )
overridevirtual

Function GetIconFileName.

Returns
a path to icon for the action plugin button

Implements ACTION_PLUGIN.

Definition at line 140 of file pcbnew_action_plugins.cpp.

141 {
142  PyLOCK lock;
143 
144  return CallRetStrMethod( "GetIconFileName" );
145 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallRetStrMethod().

◆ GetName()

wxString PYTHON_ACTION_PLUGIN::GetName ( )
overridevirtual

Function GetName.

Returns
the name of the action

Implements ACTION_PLUGIN.

Definition at line 114 of file pcbnew_action_plugins.cpp.

115 {
116  PyLOCK lock;
117 
118  return CallRetStrMethod( "GetName" );
119 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallRetStrMethod().

◆ GetObject()

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 164 of file pcbnew_action_plugins.cpp.

165 {
166  return (void*) m_PyAction;
167 }

References m_PyAction.

◆ GetPluginPath()

wxString PYTHON_ACTION_PLUGIN::GetPluginPath ( )
overridevirtual

Function GetPluginPath.

Returns
a path this plugin was loaded from

Implements ACTION_PLUGIN.

Definition at line 148 of file pcbnew_action_plugins.cpp.

149 {
150  PyLOCK lock;
151 
152  return CallRetStrMethod( "GetPluginPath" );
153 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallRetStrMethod().

◆ GetShowToolbarButton()

bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton ( )
overridevirtual

Function GetShowToolbarButton.

Returns
true if button should be shown on top toolbar

Implements ACTION_PLUGIN.

Definition at line 130 of file pcbnew_action_plugins.cpp.

131 {
132  PyLOCK lock;
133 
134  PyObject* result = CallMethod( "GetShowToolbarButton");
135 
136  return PyObject_IsTrue(result);
137 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallMethod().

◆ register_action()

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.

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...

References ACTION_PLUGINS::register_action().

Referenced by PYTHON_ACTION_PLUGINS::register_action().

◆ Run()

void PYTHON_ACTION_PLUGIN::Run ( )
overridevirtual

Function Run This method the the action.

Implements ACTION_PLUGIN.

Definition at line 156 of file pcbnew_action_plugins.cpp.

157 {
158  PyLOCK lock;
159 
160  CallMethod( "Run" );
161 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)

References CallMethod().

Member Data Documentation

◆ iconBitmap

wxBitmap ACTION_PLUGIN::iconBitmap
inherited

◆ m_actionButtonId

int ACTION_PLUGIN::m_actionButtonId
inherited

Definition at line 48 of file action_plugin.h.

Referenced by ACTION_PLUGINS::SetActionButton().

◆ m_actionMenuId

int ACTION_PLUGIN::m_actionMenuId
inherited

Definition at line 46 of file action_plugin.h.

◆ m_PyAction

PyObject* PYTHON_ACTION_PLUGIN::m_PyAction
private

◆ show_on_toolbar

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: