35 #include <wx/msgdlg.h> 36 #include "../../scripting/python_scripting.h" 43 Py_XINCREF( aAction );
62 PyObject* pFunc = PyObject_GetAttrString(
m_PyAction, aMethod );
64 if( pFunc && PyCallable_Check( pFunc ) )
66 PyObject* result = PyObject_CallObject( pFunc, aArglist );
68 if( PyErr_Occurred() )
70 wxMessageBox( PyErrStringWithTraceback(),
71 _(
"Exception on python action plugin code" ),
72 wxICON_ERROR | wxOK );
83 wxString msg =
wxString::Format(
_(
"Method '%s' not found, or not callable" ), aMethod );
84 wxMessageBox( msg,
_(
"Unknown Method" ), wxICON_ERROR | wxOK );
101 PyObject* result =
CallMethod( aMethod, aArglist );
103 ret = PyStringToWx( result );
104 Py_XDECREF( result );
138 PyObject* result =
CallMethod(
"GetShowToolbarButton");
140 return PyObject_IsTrue(result);
148 PyObject* arglist = Py_BuildValue(
"(i)", static_cast<int>( aDark ) );
152 Py_DECREF( arglist );
217 bool fromEmpty =
false;
258 aActionPlugin->
Run();
271 wxASSERT( oldBuffer );
278 std::set<BOARD_ITEM*> currItemList;
282 currItemList.insert( item );
286 currItemList.insert( item );
290 currItemList.insert( item );
294 currItemList.insert( zone );
297 for(
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
304 if( currItemList.find( item ) == currItemList.end() )
306 deletedItemsList.
PushItem( picker );
313 for(
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
325 commit.
Added( item );
335 commit.
Added( item );
345 commit.
Added( item );
355 commit.
Added( zone );
371 commit.
Push(
_(
"Apply action script" ),
false );
390 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
400 bool need_separator =
true;
410 need_separator =
false;
416 if ( ap->iconBitmap.IsOk() )
421 wxAuiToolBarItem* button =
m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
422 bitmap, ap->GetName() );
424 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
436 std::vector<ACTION_PLUGIN*> plugins;
437 std::vector<ACTION_PLUGIN*> orderedPlugins;
445 auto loc = std::find_if( plugins.begin(), plugins.end(),
448 return plugin->GetPluginPath() == pair.first;
451 if( loc != plugins.end() )
453 orderedPlugins.push_back( *loc );
454 plugins.erase( loc );
459 for(
auto remaining_plugin : plugins )
460 orderedPlugins.push_back( remaining_plugin );
462 return orderedPlugins;
467 bool aPluginDefault )
471 for(
const auto& entry : settings )
473 if( entry.first == aPluginPath )
478 return aPluginDefault;
virtual wxString GetName()=0
void OnModify() override
Must be called after a board change to set the modified flag.
This is the parent class from where any action plugin class must derive.
wxString GetName() override
COMMIT & Added(EDA_ITEM *aItem)
Remove a new item from the model.
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
void AddActionPluginTools()
Append action plugin buttons to main toolbar.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
void buildActionPluginMenus(ACTION_MENU *aActionMenu)
Fill action menu with all registered action plugins.
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
virtual wxString GetDescription()=0
wxString GetIconFileName(bool aDark) override
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void RunActionPlugin(ACTION_PLUGIN *aActionPlugin)
Execute action plugin's Run() method and updates undo buffer.
ACTION_TOOLBAR * m_mainToolBar
void register_action()
It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS singleton ma...
PCBNEW_SETTINGS * m_settings
bool GetActionPluginButtonVisible(const wxString &aPluginPath, bool aPluginDefault)
Return true if button visibility action plugin setting was set to true or it is unset and plugin defa...
unsigned GetCount() const
void OnActionPluginMenu(wxCommandEvent &aEvent)
Launched by the menu when an action is called.
COMMIT & Removed(EDA_ITEM *aItem)
Modify a given item in the model.
static void deregister_action(PyObject *aPyAction)
void * GetObject() override
This method gets the pointer to the object from where this action constructs.
wxString GetDescription() override
virtual void Run()=0
This method the the action.
static ACTION_PLUGIN * GetActionByMenu(int aMenu)
Find action plugin associated to a menu ID.
wxString GetPluginPath() override
FOOTPRINTS & Footprints()
std::vector< ACTION_PLUGIN * > GetOrderedActionPlugins()
Return ordered list of plugins in sequence in which they should appear on toolbar or in settings.
void Run() override
This method the the action.
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=nullptr)
static int GetActionsCount()
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=nullptr)
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
Handle a list of polygons defining a copper zone.
PYTHON_ACTION_PLUGIN(PyObject *action)
A holder to handle information on schematic or board items.
bool GetShowToolbarButton() override
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
static void SetActionButton(ACTION_PLUGIN *aAction, int idButton)
Associate a button id to an action plugin.
static ACTION_PLUGIN * GetAction(const wxString &aName)
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins
Information pertinent to a Pcbnew printed circuit board.
static void SetActionMenu(int aIndex, int idMenu)
Associate a menu id to an action plugin.
Class PCBNEW_ACTION_PLUGINS.
void ClearItemsList()
Delete only the list of pickers NOT the picked data itself.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
bool ContainsItem(const EDA_ITEM *aItem) const
void OnActionPluginButton(wxCommandEvent &aEvent)
Launched by the button when an action is called.
static void register_action(PyObject *aPyAction)
static bool deregister_object(void *aObject)
Deregister an object which builds a action.
static ACTION_PLUGIN * GetActionByButton(int aButton)
Find action plugin associated to a button ID.
static void SetActionRunning(bool aRunning)
wxString GetCategoryName() override