Merge ~qu1ck/kicad:plugin-icon into ~kicad-product-committers/kicad:master

Proposed by Andrew Lutsenko
Status: Superseded
Proposed branch: ~qu1ck/kicad:plugin-icon
Merge into: ~kicad-product-committers/kicad:master
Diff against target: 1837 lines (+1446/-24)
21 files modified
common/bitmap.cpp (+19/-0)
common/widgets/grid_icon_text_helpers.cpp (+40/-1)
include/bitmap_types.h (+8/-0)
include/widgets/grid_icon_text_helpers.h (+18/-1)
pcbnew/CMakeLists.txt (+7/-2)
pcbnew/action_plugin.cpp (+44/-2)
pcbnew/action_plugin.h (+49/-11)
pcbnew/dialogs/panel_pcbnew_action_plugins.cpp (+199/-0)
pcbnew/dialogs/panel_pcbnew_action_plugins.h (+59/-0)
pcbnew/dialogs/panel_pcbnew_action_plugins_base.cpp (+98/-0)
pcbnew/dialogs/panel_pcbnew_action_plugins_base.fbp (+578/-0)
pcbnew/dialogs/panel_pcbnew_action_plugins_base.h (+58/-0)
pcbnew/pcb_edit_frame.cpp (+2/-0)
pcbnew/pcb_edit_frame.h (+38/-1)
pcbnew/pcb_general_settings.cpp (+45/-0)
pcbnew/pcb_general_settings.h (+5/-0)
pcbnew/pcbnew_config.cpp (+4/-0)
pcbnew/swig/pcbnew_action_plugins.cpp (+146/-5)
pcbnew/swig/pcbnew_action_plugins.h (+3/-0)
pcbnew/tool_pcb_editor.cpp (+4/-0)
scripting/kicadplugins.i (+22/-1)
Reviewer Review Type Date Requested Status
Seth Hillbrand Needs Fixing
Jeff Young Pending
Review via email: mp+353677@code.launchpad.net

This proposal has been superseded by a proposal from 2018-08-24.

Commit message

Add toolbar buttons for action plugins

Description of the change

This adds toolbar buttons for pcbnew action plugins and a corresponding settings dialog in preferences which allows you to choose which buttons to show and their order.

To post a comment you must log in.
Revision history for this message
Seth Hillbrand (sethh) wrote :

Overall looks good. I haven't checked MacOS compatibility, so I tagged Jeff Young to comment.

The code style issues are scattered around, I think I found most all.

You should remove the unsafe/unused functions.

I don't think we should be mixing IDs between buttons and menus.

You can simplify your map usage to just a vector (O(n) is fine for searching this)

Can you squash these into a single commit (this is to allow git bisect without errors)?

review: Needs Fixing
Revision history for this message
Jeff Young (jeyjey) wrote :

I didn't try to compile it yet as my tree's in the middle of something.

~qu1ck/kicad:plugin-icon updated
f1d8129... by Andrew Lutsenko

Address review comments

Removed unused methods, switched to std::vector from map where possible,
fixed formatting and spelling.

Revision history for this message
Andrew Lutsenko (qu1ck) wrote :

Thanks for comments, I replied to all of them inline.

> Can you squash these into a single commit (this is to allow git bisect without errors)?

Can launchpad not do it on merge? If so I think I'll have to open separate merge request in the end. Will LP review system tolerate rewritten commit history?

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :
Download full text (17.6 KiB)

On 08/23/2018 05:01 PM, Seth Hillbrand wrote:
> Review: Needs Fixing
>
> Overall looks good. I haven't checked MacOS compatibility, so I tagged Jeff Young to comment.
>
> The code style issues are scattered around, I think I found most all.
>
> You should remove the unsafe/unused functions.
>
> I don't think we should be mixing IDs between buttons and menus.

@Seth, event IDs for menu and toolbar actions should be the same. In
fact wxMENU_EVENT is the same as wxTOOL_EVENT. It's merely a #define in
wxwidgets. Please use the same event ID for the toolbar and the menu
for running the same script or you will be creating a maintenance issue.

>
> You can simplify your map usage to just a vector (O(n) is fine for searching this)
>
> Can you squash these into a single commit (this is to allow git bisect without errors)?
>
> Diff comments:
>
>> diff --git a/common/widgets/grid_icon_text_helpers.cpp b/common/widgets/grid_icon_text_helpers.cpp
>> index 8d348c7..feb04bb 100644
>> --- a/common/widgets/grid_icon_text_helpers.cpp
>> +++ b/common/widgets/grid_icon_text_helpers.cpp
>> @@ -68,6 +68,45 @@ void GRID_CELL_ICON_TEXT_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, w
>> aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
>> }
>>
>> +//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
>> +//
>> +// Note: this renderer is supposed to be used with read only cells
>> +
>> +GRID_CELL_ICON_RENDERER::GRID_CELL_ICON_RENDERER(const wxBitmap& icon) : m_icon( icon )
>> +{
>> +}
>> +
>> +
>> +void GRID_CELL_ICON_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
>> + const wxRect& aRect, int aRow, int aCol, bool isSelected )
>> +{
>> + wxRect rect = aRect;
>> + rect.Inflate( -1 );
>> +
>> + // erase background
>> + wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
>> +
>> + // Draw icon
>> + if( m_icon.IsOk() )
>> + {
>> + aDC.DrawBitmap( m_icon,
>> + rect.GetLeft() + (rect.GetWidth() - m_icon.GetWidth()) / 2,
>
> Whitespace here around parentheses
>
>> + rect.GetTop() + (rect.GetHeight() - m_icon.GetHeight()) / 2,
>> + true );
>> + }
>> +}
>> +
>> +
>> +wxSize GRID_CELL_ICON_RENDERER::GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col)
>
> Whitespace here around parentheses.
>
>> +{
>> + return wxSize( m_icon.GetWidth() + 6, m_icon.GetHeight() + 4 );
>> +}
>> +
>> +
>> +wxGridCellRenderer* GRID_CELL_ICON_RENDERER::Clone() const
>> +{
>> + return new GRID_CELL_ICON_RENDERER( m_icon );
>> +}
>>
>>
>> //---- Grid helpers: custom wxGridCellEditor ------------------------------------------
>> diff --git a/include/widgets/grid_icon_text_helpers.h b/include/widgets/grid_icon_text_helpers.h
>> index 9e14829..e859f11 100644
>> --- a/include/widgets/grid_icon_text_helpers.h
>> +++ b/include/widgets/grid_icon_text_helpers.h
>> @@ -49,6 +49,23 @@ private:
>> const wxArrayString& m_names;
>> };
>>
>> +//---- Grid helpers: custom wxGridCellRenderer that re...

Revision history for this message
Seth Hillbrand (sethh) wrote :

@Wayne- My comment here was unclear. The IDs are generated by wx when the menu items are added and a different ID is generated when the toolbar button is added. However, they are linked in the same callback handler, checking first for the menu button ID in the event and then, failing that, for the toolbar button ID. My concern was that separating the event handling based on wx's autogenerated IDs makes an assumption about the IDs. I'd feel better about that line if the handler split based on an event type and then did the ID lookup in the related list.

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@Seth, got it. I don't have any further issues.

Unmerged commits

f1d8129... by Andrew Lutsenko

Address review comments

Removed unused methods, switched to std::vector from map where possible,
fixed formatting and spelling.

45669dc... by Andrew Lutsenko

Scale plugin icons on toolbar

502265b... by Andrew Lutsenko

Fix bug with plugin order when one is removed and another added

Also fix formatting

8132d0f... by Andrew Lutsenko

Adjust action plugins grid properties

49a6578... by Andrew Lutsenko

Fix build with actions menu disabled

1678522... by Andrew Lutsenko

Don't show error on icon load failure

81228af... by Andrew Lutsenko

Add action plugin ordering buttons in preferences

ddd8f73... by Andrew Lutsenko

Store and read action plugin settings display buttons accordingly

b0ddbcd... by Andrew Lutsenko

Add category, description and path to action plugin grid

2c3aa9e... by Andrew Lutsenko

Load action plugin list in pcbnew prefs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/common/bitmap.cpp b/common/bitmap.cpp
2index 031b2cc..bce8344 100644
3--- a/common/bitmap.cpp
4+++ b/common/bitmap.cpp
5@@ -144,6 +144,25 @@ wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow )
6 }
7
8
9+wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow )
10+{
11+ const int scale = get_scale_factor( aWindow );
12+
13+ if( scale == 4)
14+ {
15+ return wxBitmap( aBitmap );
16+ }
17+ else
18+ {
19+ wxImage image = aBitmap.ConvertToImage();
20+ image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
21+ wxIMAGE_QUALITY_BILINEAR );
22+
23+ return wxBitmap( image );
24+ }
25+}
26+
27+
28 void KiScaledSeparator( wxAuiToolBar* aToolbar, EDA_BASE_FRAME* aWindow )
29 {
30 const int scale = get_scale_factor( aWindow );
31diff --git a/common/widgets/grid_icon_text_helpers.cpp b/common/widgets/grid_icon_text_helpers.cpp
32index 8d348c7..b1f949e 100644
33--- a/common/widgets/grid_icon_text_helpers.cpp
34+++ b/common/widgets/grid_icon_text_helpers.cpp
35@@ -27,7 +27,7 @@
36 #include <wx/dc.h>
37
38
39-//---- Grid helpers: custom wxGridCellRenderer ------------------------------------------
40+//---- Grid helpers: custom wxGridCellRenderer that renders icon and a label ------------
41
42
43 GRID_CELL_ICON_TEXT_RENDERER::GRID_CELL_ICON_TEXT_RENDERER( const std::vector<BITMAP_DEF>& icons,
44@@ -68,6 +68,45 @@ void GRID_CELL_ICON_TEXT_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, w
45 aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
46 }
47
48+//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
49+//
50+// Note: this renderer is supposed to be used with read only cells
51+
52+GRID_CELL_ICON_RENDERER::GRID_CELL_ICON_RENDERER(const wxBitmap& icon) : m_icon( icon )
53+{
54+}
55+
56+
57+void GRID_CELL_ICON_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
58+ const wxRect& aRect, int aRow, int aCol, bool isSelected )
59+{
60+ wxRect rect = aRect;
61+ rect.Inflate( -1 );
62+
63+ // erase background
64+ wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
65+
66+ // Draw icon
67+ if( m_icon.IsOk() )
68+ {
69+ aDC.DrawBitmap( m_icon,
70+ rect.GetLeft() + ( rect.GetWidth() - m_icon.GetWidth() ) / 2,
71+ rect.GetTop() + ( rect.GetHeight() - m_icon.GetHeight() ) / 2,
72+ true );
73+ }
74+}
75+
76+
77+wxSize GRID_CELL_ICON_RENDERER::GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col )
78+{
79+ return wxSize( m_icon.GetWidth() + 6, m_icon.GetHeight() + 4 );
80+}
81+
82+
83+wxGridCellRenderer* GRID_CELL_ICON_RENDERER::Clone() const
84+{
85+ return new GRID_CELL_ICON_RENDERER( m_icon );
86+}
87
88
89 //---- Grid helpers: custom wxGridCellEditor ------------------------------------------
90diff --git a/include/bitmap_types.h b/include/bitmap_types.h
91index 8657df4..f703ddb 100644
92--- a/include/bitmap_types.h
93+++ b/include/bitmap_types.h
94@@ -73,6 +73,14 @@ wxBitmap KiBitmap( BITMAP_DEF aBitmap );
95 */
96 wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow );
97
98+/**
99+ * Function KiScaledBitmap
100+ * Overload of the above function that takes another wxBitmap as a parameter
101+ *
102+ * @param aBitmap bitmap definition
103+ * @param aWindow target window for scaling context
104+ */
105+wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow );
106
107 /**
108 * Function KiScaledSeparator
109diff --git a/include/widgets/grid_icon_text_helpers.h b/include/widgets/grid_icon_text_helpers.h
110index 9e14829..60ea612 100644
111--- a/include/widgets/grid_icon_text_helpers.h
112+++ b/include/widgets/grid_icon_text_helpers.h
113@@ -34,7 +34,7 @@
114 class wxGrid;
115
116
117-//---- Grid helpers: custom wxGridCellRenderer ------------------------------------------
118+//---- Grid helpers: custom wxGridCellRenderer that renders icon and a label ------------
119
120 class GRID_CELL_ICON_TEXT_RENDERER : public wxGridCellStringRenderer
121 {
122@@ -49,6 +49,23 @@ private:
123 const wxArrayString& m_names;
124 };
125
126+//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
127+//
128+// Note: use with read only cells
129+
130+class GRID_CELL_ICON_RENDERER : public wxGridCellRenderer
131+{
132+public:
133+ GRID_CELL_ICON_RENDERER( const wxBitmap& icon );
134+
135+ void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
136+ const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
137+ wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row, int col ) override;
138+ wxGridCellRenderer* Clone() const override;
139+
140+private:
141+ const wxBitmap& m_icon;
142+};
143
144 //---- Grid helpers: custom wxGridCellEditor ------------------------------------------
145 //
146diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
147index d9f55dd..a666703 100644
148--- a/pcbnew/CMakeLists.txt
149+++ b/pcbnew/CMakeLists.txt
150@@ -152,8 +152,6 @@ set( PCBNEW_DIALOGS
151 dialogs/panel_modedit_settings_base.cpp
152 dialogs/panel_pcbnew_display_options.cpp
153 dialogs/panel_pcbnew_display_options_base.cpp
154- dialogs/panel_pcbnew_display_options.cpp
155- dialogs/panel_pcbnew_display_options_base.cpp
156 dialogs/panel_pcbnew_settings.cpp
157 dialogs/panel_pcbnew_settings_base.cpp
158 dialogs/panel_setup_mask_and_paste.cpp
159@@ -174,6 +172,13 @@ set( PCBNEW_DIALOGS
160 ${GITHUB_3DLIBRARIES_WIZARD}
161 )
162
163+if( KICAD_SCRIPTING AND KICAD_SCRIPTING_ACTION_MENU )
164+ set( PCBNEW_DIALOGS ${PCBNEW_DIALOGS}
165+ dialogs/panel_pcbnew_action_plugins.cpp
166+ dialogs/panel_pcbnew_action_plugins_base.cpp
167+ )
168+endif()
169+
170 set( PCBNEW_IMPORT_DXF
171 import_dxf/dialog_dxf_import.cpp
172 import_dxf/dialog_dxf_import_base.cpp
173diff --git a/pcbnew/action_plugin.cpp b/pcbnew/action_plugin.cpp
174index c10d0fa..e79ea29 100644
175--- a/pcbnew/action_plugin.cpp
176+++ b/pcbnew/action_plugin.cpp
177@@ -73,9 +73,37 @@ void ACTION_PLUGINS::SetActionMenu( int aIndex, int idMenu )
178 }
179
180
181-int ACTION_PLUGINS::GetActionMenu( int aIndex )
182+ACTION_PLUGIN* ACTION_PLUGINS::GetActionByButton( int aButton )
183 {
184- return m_actionsList[aIndex]->m_actionMenuId;
185+ int max = GetActionsCount();
186+
187+ for( int i = 0; i < max; i++ )
188+ {
189+ if( m_actionsList[i]->m_actionButtonId == aButton )
190+ return m_actionsList[i];
191+ }
192+
193+ return NULL;
194+}
195+
196+
197+void ACTION_PLUGINS::SetActionButton( ACTION_PLUGIN* aAction, int idButton )
198+{
199+ aAction->m_actionButtonId = idButton;
200+}
201+
202+
203+ACTION_PLUGIN* ACTION_PLUGINS::GetActionByPath(const wxString& aPath)
204+{
205+ for( int i = 0; i < GetActionsCount() ; i++ )
206+ {
207+ if( m_actionsList[i]->GetPluginPath() == aPath)
208+ {
209+ return m_actionsList[i];
210+ }
211+ }
212+
213+ return NULL;
214 }
215
216
217@@ -127,6 +155,20 @@ void ACTION_PLUGINS::register_action( ACTION_PLUGIN* aAction )
218 }
219 }
220
221+ // Load icon if supplied
222+ if (!aAction->GetIconFileName().IsEmpty())
223+ {
224+ {
225+ wxLogNull eat_errors;
226+ aAction->iconBitmap.LoadFile( aAction->GetIconFileName() , wxBITMAP_TYPE_PNG );
227+ }
228+
229+ if ( !aAction->iconBitmap.IsOk() )
230+ {
231+ wxLogVerbose( "Failed to load icon " + aAction->GetIconFileName() + " for action plugin " );
232+ }
233+ }
234+
235 m_actionsList.push_back( aAction );
236 }
237
238diff --git a/pcbnew/action_plugin.h b/pcbnew/action_plugin.h
239index ff3ed14..8bb6c9c 100644
240--- a/pcbnew/action_plugin.h
241+++ b/pcbnew/action_plugin.h
242@@ -44,9 +44,16 @@ public:
243 // m_actionMenuId set to 0 means the corresponding menuitem to call this
244 // action is not yet created
245 int m_actionMenuId;
246+ // Same for button id
247+ int m_actionButtonId;
248+ // Icon for the action button and menu entry
249+ wxBitmap iconBitmap;
250+ // If show_on_toolbar is true a button will be added to top toolbar
251+ bool show_on_toolbar;
252
253 public:
254- ACTION_PLUGIN() : m_actionMenuId( 0 ) {}
255+ ACTION_PLUGIN() : m_actionMenuId( 0 ), m_actionButtonId( 0 ),
256+ show_on_toolbar( false ) {}
257 virtual ~ACTION_PLUGIN();
258
259 /**
260@@ -69,6 +76,24 @@ public:
261 virtual wxString GetDescription() = 0;
262
263 /**
264+ * Function GetShowToolbarButton
265+ * @return true if button should be shown on top toolbar
266+ */
267+ virtual bool GetShowToolbarButton() = 0;
268+
269+ /**
270+ * Function GetIconFileName
271+ * @return a path to icon for the action plugin button
272+ */
273+ virtual wxString GetIconFileName() = 0;
274+
275+ /**
276+ * Function GetPluginPath
277+ * @return a path this plugin was loaded from
278+ */
279+ virtual wxString GetPluginPath() = 0;
280+
281+ /**
282 * Function GetObject
283 * This method gets the pointer to the object from where this action constructs
284 * @return it's a void pointer, as it could be a PyObject or any other
285@@ -137,16 +162,6 @@ public:
286 */
287 static void SetActionMenu( int aIndex, int idMenu );
288
289-
290- /**
291- * Function GetActionMenu
292- * Provide menu id for a plugin index
293- * @param aIndex is the action index
294- * @return associated menuitem id
295- */
296- static int GetActionMenu( int aIndex );
297-
298-
299 /**
300 * Function GetActionByMenu
301 * find action plugin associated to a menu id
302@@ -155,6 +170,29 @@ public:
303 */
304 static ACTION_PLUGIN* GetActionByMenu( int aMenu );
305
306+ /**
307+ * Function SetActionButton
308+ * Associate a button id to an action plugin
309+ * @param aAction is the action
310+ * @param idButton is the associated menuitem id
311+ */
312+ static void SetActionButton( ACTION_PLUGIN* aAction, int idButton );
313+
314+ /**
315+ * Function GetActionByButton
316+ * find action plugin associated to a button id
317+ * @param aButton is the button id (defined with SetActionButton)
318+ * @return the associated ACTION_PLUGIN (or null if not found)
319+ */
320+ static ACTION_PLUGIN* GetActionByButton( int aButton );
321+
322+ /**
323+ * Function GetActionByPath
324+ * find action plugin by module path
325+ * @param aPath the path of plugin
326+ * @return the corresponding ACTION_PLUGIN (or null if not found)
327+ */
328+ static ACTION_PLUGIN* GetActionByPath( const wxString& aPath );
329
330 /**
331 * Function GetAction
332diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp
333new file mode 100644
334index 0000000..5ad31de
335--- /dev/null
336+++ b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp
337@@ -0,0 +1,199 @@
338+/*
339+ * This program source code file is part of KiCad, a free EDA CAD application.
340+ *
341+ * Copyright (C) 2018 Andrew Lutsenko, anlutsenko at gmail dot com
342+ * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
343+ *
344+ * This program is free software: you can redistribute it and/or modify it
345+ * under the terms of the GNU General Public License as published by the
346+ * Free Software Foundation, either version 3 of the License, or (at your
347+ * option) any later version.
348+ *
349+ * This program is distributed in the hope that it will be useful, but
350+ * WITHOUT ANY WARRANTY; without even the implied warranty of
351+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
352+ * General Public License for more details.
353+ *
354+ * You should have received a copy of the GNU General Public License along
355+ * with this program. If not, see <http://www.gnu.org/licenses/>.
356+ */
357+
358+#include <pcb_edit_frame.h>
359+#include <panel_pcbnew_action_plugins.h>
360+#include <widgets/paged_dialog.h>
361+#include <widgets/grid_icon_text_helpers.h>
362+#include <bitmaps.h>
363+#include <action_plugin.h>
364+#include <grid_tricks.h>
365+#include <widgets/wx_grid.h>
366+
367+
368+PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS( PCB_EDIT_FRAME* aFrame, PAGED_DIALOG* aWindow ) :
369+ PANEL_PCBNEW_ACTION_PLUGINS_BASE( aWindow->GetTreebook() ),
370+ m_frame( aFrame )
371+{
372+ m_genericIcon = KiBitmap( hammer_xpm );
373+ m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
374+
375+ m_moveUpButton->SetBitmap( KiBitmap( up_xpm ) );
376+ m_moveDownButton->SetBitmap( KiBitmap( down_xpm ) );
377+ m_reloadButton->SetBitmap( KiBitmap( refresh_xpm ) );
378+}
379+
380+
381+PANEL_PCBNEW_ACTION_PLUGINS::~PANEL_PCBNEW_ACTION_PLUGINS()
382+{
383+ m_grid->PopEventHandler( true );
384+}
385+
386+
387+void PANEL_PCBNEW_ACTION_PLUGINS::OnGridCellClick( wxGridEvent& event )
388+{
389+ SelectRow( event.GetRow() );
390+}
391+
392+
393+void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow( int aRow )
394+{
395+ m_grid->ClearSelection();
396+ m_grid->SelectRow( aRow );
397+}
398+
399+
400+void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event )
401+{
402+ auto selectedRows = m_grid->GetSelectedRows();
403+
404+ // If nothing is selected or multiple rows are selected don't do anything.
405+ if( selectedRows.size() != 1 ) return;
406+
407+ int selectedRow = selectedRows[0];
408+
409+ // If first row is selected, then it can't go any further up.
410+ if( selectedRow == 0 )
411+ {
412+ wxBell();
413+ return;
414+ }
415+
416+ SwapRows( selectedRow, selectedRow - 1 );
417+
418+ SelectRow( selectedRow - 1 );
419+}
420+
421+
422+void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event )
423+{
424+ auto selectedRows = m_grid->GetSelectedRows();
425+
426+ // If nothing is selected or multiple rows are selected don't do anything.
427+ if( selectedRows.size() != 1 ) return;
428+
429+ int selectedRow = selectedRows[0];
430+
431+ // If last row is selected, then it can't go any further down.
432+ if( selectedRow + 1 == m_grid->GetNumberRows() )
433+ {
434+ wxBell();
435+ return;
436+ }
437+
438+ SwapRows( selectedRow, selectedRow + 1 );
439+
440+ SelectRow( selectedRow + 1 );
441+}
442+
443+
444+void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows( int aRowA, int aRowB )
445+{
446+ m_grid->Freeze();
447+
448+ // Swap all columns except icon
449+ wxString tempStr;
450+
451+ for( int column = 1; column < m_grid->GetNumberCols(); column++ )
452+ {
453+ tempStr = m_grid->GetCellValue( aRowA, column );
454+ m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
455+ m_grid->SetCellValue( aRowB, column, tempStr );
456+ }
457+
458+ // Swap icon column renderers
459+ auto cellRenderer = m_grid->GetCellRenderer( aRowA, 0 );
460+ m_grid->SetCellRenderer( aRowA, 0, m_grid->GetCellRenderer( aRowB, 0 ) );
461+ m_grid->SetCellRenderer( aRowB, 0, cellRenderer );
462+
463+ m_grid->Thaw();
464+}
465+
466+
467+void PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick( wxCommandEvent& event )
468+{
469+ m_frame->PythonPluginsReload();
470+ TransferDataToWindow();
471+}
472+
473+
474+bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow()
475+{
476+ std::vector< std::pair<wxString, wxString> > pluginSettings;
477+
478+ for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
479+ {
480+ pluginSettings.push_back( std::make_pair(
481+ m_grid->GetCellValue( ii, 5 ),
482+ m_grid->GetCellValue( ii, 1 ) == wxT("1") ? wxT( "Visible" ) : wxT( "Hidden" )
483+ ) );
484+ }
485+
486+ m_frame->SetActionPluginSettings( pluginSettings );
487+
488+ return true;
489+}
490+
491+
492+bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
493+{
494+ m_grid->Freeze();
495+ m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
496+
497+ const auto& orderedPlugins = m_frame->GetOrderedActionPlugins();
498+ m_grid->AppendRows( orderedPlugins.size() );
499+
500+ for( size_t row = 0; row < orderedPlugins.size(); row++ )
501+ {
502+ ACTION_PLUGIN* ap = orderedPlugins[row];
503+
504+ // Icon
505+ m_grid->SetCellRenderer( row, 0, new GRID_CELL_ICON_RENDERER(
506+ ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
507+
508+ // Toolbar button checkbox
509+ m_grid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
510+ m_grid->SetCellAlignment( row, 1, wxALIGN_CENTER, wxALIGN_CENTER );
511+
512+ bool showButton = m_frame->GetActionPluginButtonVisible(
513+ ap->GetPluginPath(), ap->GetShowToolbarButton() );
514+
515+ m_grid->SetCellValue( row, 1, showButton ? wxT( "1" ) : wxEmptyString );
516+
517+ // Name
518+ m_grid->SetCellValue( row, 2, ap->GetName() );
519+
520+ // Category
521+ m_grid->SetCellValue( row, 3, ap->GetCategoryName() );
522+
523+ // Description
524+ m_grid->SetCellValue( row, 4, ap->GetDescription() );
525+
526+ // Path
527+ m_grid->SetCellValue( row, 5, ap->GetPluginPath() );
528+ }
529+
530+ m_grid->AutoSizeColumns();
531+ m_grid->AutoSizeRows();
532+
533+ m_grid->Thaw();
534+
535+ return true;
536+}
537diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins.h b/pcbnew/dialogs/panel_pcbnew_action_plugins.h
538new file mode 100644
539index 0000000..e36b06c
540--- /dev/null
541+++ b/pcbnew/dialogs/panel_pcbnew_action_plugins.h
542@@ -0,0 +1,59 @@
543+/*
544+ * This program source code file is part of KiCad, a free EDA CAD application.
545+ *
546+ * Copyright (C) 2018 Andrew Lutsenko, anlutsenko at gmail dot com
547+ * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
548+ *
549+ * This program is free software: you can redistribute it and/or modify it
550+ * under the terms of the GNU General Public License as published by the
551+ * Free Software Foundation, either version 3 of the License, or (at your
552+ * option) any later version.
553+ *
554+ * This program is distributed in the hope that it will be useful, but
555+ * WITHOUT ANY WARRANTY; without even the implied warranty of
556+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
557+ * General Public License for more details.
558+ *
559+ * You should have received a copy of the GNU General Public License along
560+ * with this program. If not, see <http://www.gnu.org/licenses/>.
561+ */
562+
563+#include "panel_pcbnew_action_plugins_base.h"
564+
565+class PANEL_PCBNEW_ACTION_PLUGINS : public PANEL_PCBNEW_ACTION_PLUGINS_BASE
566+{
567+public:
568+ PANEL_PCBNEW_ACTION_PLUGINS ( PCB_EDIT_FRAME* aFrame, PAGED_DIALOG* aWindow );
569+
570+ bool TransferDataFromWindow() override;
571+ bool TransferDataToWindow() override;
572+ ~PANEL_PCBNEW_ACTION_PLUGINS() override;
573+
574+ /**
575+ * Selects a whole row
576+ */
577+ void OnGridCellClick( wxGridEvent& event ) override;
578+
579+ /**
580+ * Moves plugin up in the grid
581+ */
582+ void OnMoveUpButtonClick( wxCommandEvent& event ) override;
583+
584+ /**
585+ * Moves plugin down in the grid
586+ */
587+ void OnMoveDownButtonClick( wxCommandEvent& event ) override;
588+
589+ /**
590+ * Reloads plugins and updates grid
591+ */
592+ void OnReloadButtonClick( wxCommandEvent& event ) override;
593+
594+private:
595+ PCB_EDIT_FRAME* m_frame;
596+ wxBitmap m_genericIcon;
597+
598+ void SwapRows( int aRowA, int aRowB );
599+ void SelectRow( int aRow );
600+};
601+
602diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins_base.cpp b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.cpp
603new file mode 100644
604index 0000000..d8f8909
605--- /dev/null
606+++ b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.cpp
607@@ -0,0 +1,98 @@
608+///////////////////////////////////////////////////////////////////////////
609+// C++ code generated with wxFormBuilder (version Jul 11 2018)
610+// http://www.wxformbuilder.org/
611+//
612+// PLEASE DO *NOT* EDIT THIS FILE!
613+///////////////////////////////////////////////////////////////////////////
614+
615+#include "widgets/wx_grid.h"
616+
617+#include "panel_pcbnew_action_plugins_base.h"
618+
619+///////////////////////////////////////////////////////////////////////////
620+
621+PANEL_PCBNEW_ACTION_PLUGINS_BASE::PANEL_PCBNEW_ACTION_PLUGINS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style )
622+{
623+ wxBoxSizer* bPanelSizer;
624+ bPanelSizer = new wxBoxSizer( wxHORIZONTAL );
625+
626+ wxBoxSizer* bGridSizer;
627+ bGridSizer = new wxBoxSizer( wxVERTICAL );
628+
629+ m_grid = new WX_GRID( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE );
630+
631+ // Grid
632+ m_grid->CreateGrid( 3, 6 );
633+ m_grid->EnableEditing( false );
634+ m_grid->EnableGridLines( true );
635+ m_grid->EnableDragGridSize( false );
636+ m_grid->SetMargins( 0, 0 );
637+
638+ // Columns
639+ m_grid->AutoSizeColumns();
640+ m_grid->EnableDragColMove( false );
641+ m_grid->EnableDragColSize( true );
642+ m_grid->SetColLabelSize( 22 );
643+ m_grid->SetColLabelValue( 0, wxT("Icon") );
644+ m_grid->SetColLabelValue( 1, wxT("Show button") );
645+ m_grid->SetColLabelValue( 2, wxT("Name") );
646+ m_grid->SetColLabelValue( 3, wxT("Category") );
647+ m_grid->SetColLabelValue( 4, wxT("Description") );
648+ m_grid->SetColLabelValue( 5, wxT("Path") );
649+ m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
650+
651+ // Rows
652+ m_grid->EnableDragRowSize( true );
653+ m_grid->SetRowLabelSize( 0 );
654+ m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
655+
656+ // Label Appearance
657+
658+ // Cell Defaults
659+ m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
660+ bGridSizer->Add( m_grid, 1, wxALL|wxEXPAND, 5 );
661+
662+
663+ bPanelSizer->Add( bGridSizer, 1, wxALIGN_LEFT|wxEXPAND|wxLEFT, 0 );
664+
665+ wxBoxSizer* bButtonsSizer;
666+ bButtonsSizer = new wxBoxSizer( wxVERTICAL );
667+
668+ m_moveUpButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
669+ m_moveUpButton->SetMinSize( wxSize( 32,32 ) );
670+
671+ bButtonsSizer->Add( m_moveUpButton, 0, wxALIGN_TOP|wxALL, 5 );
672+
673+ m_moveDownButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
674+ m_moveDownButton->SetMinSize( wxSize( 32,32 ) );
675+
676+ bButtonsSizer->Add( m_moveDownButton, 0, wxALL, 5 );
677+
678+ m_reloadButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
679+ m_reloadButton->SetMinSize( wxSize( 32,32 ) );
680+
681+ bButtonsSizer->Add( m_reloadButton, 0, wxALL, 5 );
682+
683+
684+ bPanelSizer->Add( bButtonsSizer, 0, wxALIGN_RIGHT|wxALIGN_TOP, 0 );
685+
686+
687+ this->SetSizer( bPanelSizer );
688+ this->Layout();
689+
690+ // Connect Events
691+ m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnGridCellClick ), NULL, this );
692+ m_moveUpButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnMoveUpButtonClick ), NULL, this );
693+ m_moveDownButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnMoveDownButtonClick ), NULL, this );
694+ m_reloadButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnReloadButtonClick ), NULL, this );
695+}
696+
697+PANEL_PCBNEW_ACTION_PLUGINS_BASE::~PANEL_PCBNEW_ACTION_PLUGINS_BASE()
698+{
699+ // Disconnect Events
700+ m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnGridCellClick ), NULL, this );
701+ m_moveUpButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnMoveUpButtonClick ), NULL, this );
702+ m_moveDownButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnMoveDownButtonClick ), NULL, this );
703+ m_reloadButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PCBNEW_ACTION_PLUGINS_BASE::OnReloadButtonClick ), NULL, this );
704+
705+}
706diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins_base.fbp b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.fbp
707new file mode 100644
708index 0000000..6c91f1f
709--- /dev/null
710+++ b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.fbp
711@@ -0,0 +1,578 @@
712+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
713+<wxFormBuilder_Project>
714+ <FileVersion major="1" minor="14" />
715+ <object class="Project" expanded="1">
716+ <property name="class_decoration"></property>
717+ <property name="code_generation">C++</property>
718+ <property name="disconnect_events">1</property>
719+ <property name="disconnect_mode">source_name</property>
720+ <property name="disconnect_php_events">0</property>
721+ <property name="disconnect_python_events">0</property>
722+ <property name="embedded_files_path">res</property>
723+ <property name="encoding">UTF-8</property>
724+ <property name="event_generation">connect</property>
725+ <property name="file">panel_pcbnew_action_plugins_base</property>
726+ <property name="first_id">1000</property>
727+ <property name="help_provider">none</property>
728+ <property name="indent_with_spaces">0</property>
729+ <property name="internationalize">0</property>
730+ <property name="name">PanelPcbnewActionPlugins</property>
731+ <property name="namespace"></property>
732+ <property name="path">.</property>
733+ <property name="precompiled_header"></property>
734+ <property name="relative_path">1</property>
735+ <property name="skip_lua_events">1</property>
736+ <property name="skip_php_events">1</property>
737+ <property name="skip_python_events">1</property>
738+ <property name="ui_table">UI</property>
739+ <property name="use_enum">1</property>
740+ <property name="use_microsoft_bom">0</property>
741+ <object class="Panel" expanded="1">
742+ <property name="aui_managed">0</property>
743+ <property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
744+ <property name="bg"></property>
745+ <property name="context_help"></property>
746+ <property name="context_menu">1</property>
747+ <property name="enabled">1</property>
748+ <property name="event_handler">impl_virtual</property>
749+ <property name="fg"></property>
750+ <property name="font"></property>
751+ <property name="hidden">0</property>
752+ <property name="id">wxID_ANY</property>
753+ <property name="maximum_size"></property>
754+ <property name="minimum_size"></property>
755+ <property name="name">PANEL_PCBNEW_ACTION_PLUGINS_BASE</property>
756+ <property name="pos"></property>
757+ <property name="size">485,200</property>
758+ <property name="subclass">; forward_declare</property>
759+ <property name="tooltip"></property>
760+ <property name="window_extra_style"></property>
761+ <property name="window_name"></property>
762+ <property name="window_style">wxTAB_TRAVERSAL</property>
763+ <event name="OnAuiPaneActivated"></event>
764+ <event name="OnAuiPaneButton"></event>
765+ <event name="OnAuiPaneClose"></event>
766+ <event name="OnAuiPaneMaximize"></event>
767+ <event name="OnAuiPaneRestore"></event>
768+ <event name="OnAuiRender"></event>
769+ <event name="OnAux1DClick"></event>
770+ <event name="OnAux1Down"></event>
771+ <event name="OnAux1Up"></event>
772+ <event name="OnAux2DClick"></event>
773+ <event name="OnAux2Down"></event>
774+ <event name="OnAux2Up"></event>
775+ <event name="OnChar"></event>
776+ <event name="OnCharHook"></event>
777+ <event name="OnEnterWindow"></event>
778+ <event name="OnEraseBackground"></event>
779+ <event name="OnInitDialog"></event>
780+ <event name="OnKeyDown"></event>
781+ <event name="OnKeyUp"></event>
782+ <event name="OnKillFocus"></event>
783+ <event name="OnLeaveWindow"></event>
784+ <event name="OnLeftDClick"></event>
785+ <event name="OnLeftDown"></event>
786+ <event name="OnLeftUp"></event>
787+ <event name="OnMiddleDClick"></event>
788+ <event name="OnMiddleDown"></event>
789+ <event name="OnMiddleUp"></event>
790+ <event name="OnMotion"></event>
791+ <event name="OnMouseEvents"></event>
792+ <event name="OnMouseWheel"></event>
793+ <event name="OnPaint"></event>
794+ <event name="OnRightDClick"></event>
795+ <event name="OnRightDown"></event>
796+ <event name="OnRightUp"></event>
797+ <event name="OnSetFocus"></event>
798+ <event name="OnSize"></event>
799+ <event name="OnUpdateUI"></event>
800+ <object class="wxBoxSizer" expanded="1">
801+ <property name="minimum_size"></property>
802+ <property name="name">bPanelSizer</property>
803+ <property name="orient">wxHORIZONTAL</property>
804+ <property name="permission">none</property>
805+ <object class="sizeritem" expanded="1">
806+ <property name="border">0</property>
807+ <property name="flag">wxALIGN_LEFT|wxEXPAND|wxLEFT</property>
808+ <property name="proportion">1</property>
809+ <object class="wxBoxSizer" expanded="1">
810+ <property name="minimum_size"></property>
811+ <property name="name">bGridSizer</property>
812+ <property name="orient">wxVERTICAL</property>
813+ <property name="permission">none</property>
814+ <object class="sizeritem" expanded="1">
815+ <property name="border">5</property>
816+ <property name="flag">wxALL|wxEXPAND</property>
817+ <property name="proportion">1</property>
818+ <object class="wxGrid" expanded="1">
819+ <property name="BottomDockable">1</property>
820+ <property name="LeftDockable">1</property>
821+ <property name="RightDockable">1</property>
822+ <property name="TopDockable">1</property>
823+ <property name="aui_layer"></property>
824+ <property name="aui_name"></property>
825+ <property name="aui_position"></property>
826+ <property name="aui_row"></property>
827+ <property name="autosize_cols">1</property>
828+ <property name="autosize_rows">0</property>
829+ <property name="best_size"></property>
830+ <property name="bg"></property>
831+ <property name="caption"></property>
832+ <property name="caption_visible">1</property>
833+ <property name="cell_bg"></property>
834+ <property name="cell_font"></property>
835+ <property name="cell_horiz_alignment">wxALIGN_LEFT</property>
836+ <property name="cell_text"></property>
837+ <property name="cell_vert_alignment">wxALIGN_CENTRE</property>
838+ <property name="center_pane">0</property>
839+ <property name="close_button">1</property>
840+ <property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
841+ <property name="col_label_size">22</property>
842+ <property name="col_label_values">&quot;Icon&quot; &quot;Show button&quot; &quot;Name&quot; &quot;Category&quot; &quot;Description&quot; &quot;Path&quot;</property>
843+ <property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
844+ <property name="cols">6</property>
845+ <property name="column_sizes"></property>
846+ <property name="context_help"></property>
847+ <property name="context_menu">1</property>
848+ <property name="default_pane">0</property>
849+ <property name="dock">Dock</property>
850+ <property name="dock_fixed">0</property>
851+ <property name="docking">Left</property>
852+ <property name="drag_col_move">0</property>
853+ <property name="drag_col_size">1</property>
854+ <property name="drag_grid_size">0</property>
855+ <property name="drag_row_size">1</property>
856+ <property name="editing">0</property>
857+ <property name="enabled">1</property>
858+ <property name="fg"></property>
859+ <property name="floatable">1</property>
860+ <property name="font"></property>
861+ <property name="grid_line_color"></property>
862+ <property name="grid_lines">1</property>
863+ <property name="gripper">0</property>
864+ <property name="hidden">0</property>
865+ <property name="id">wxID_ANY</property>
866+ <property name="label_bg"></property>
867+ <property name="label_font"></property>
868+ <property name="label_text"></property>
869+ <property name="margin_height">0</property>
870+ <property name="margin_width">0</property>
871+ <property name="max_size"></property>
872+ <property name="maximize_button">0</property>
873+ <property name="maximum_size"></property>
874+ <property name="min_size"></property>
875+ <property name="minimize_button">0</property>
876+ <property name="minimum_size"></property>
877+ <property name="moveable">1</property>
878+ <property name="name">m_grid</property>
879+ <property name="pane_border">1</property>
880+ <property name="pane_position"></property>
881+ <property name="pane_size"></property>
882+ <property name="permission">protected</property>
883+ <property name="pin_button">1</property>
884+ <property name="pos"></property>
885+ <property name="resize">Resizable</property>
886+ <property name="row_label_horiz_alignment">wxALIGN_CENTRE</property>
887+ <property name="row_label_size">0</property>
888+ <property name="row_label_values"></property>
889+ <property name="row_label_vert_alignment">wxALIGN_CENTRE</property>
890+ <property name="row_sizes"></property>
891+ <property name="rows">3</property>
892+ <property name="show">1</property>
893+ <property name="size"></property>
894+ <property name="subclass">WX_GRID; widgets/wx_grid.h; forward_declare</property>
895+ <property name="toolbar_pane">0</property>
896+ <property name="tooltip"></property>
897+ <property name="window_extra_style"></property>
898+ <property name="window_name"></property>
899+ <property name="window_style">wxBORDER_SIMPLE</property>
900+ <event name="OnAux1DClick"></event>
901+ <event name="OnAux1Down"></event>
902+ <event name="OnAux1Up"></event>
903+ <event name="OnAux2DClick"></event>
904+ <event name="OnAux2Down"></event>
905+ <event name="OnAux2Up"></event>
906+ <event name="OnChar"></event>
907+ <event name="OnCharHook"></event>
908+ <event name="OnEnterWindow"></event>
909+ <event name="OnEraseBackground"></event>
910+ <event name="OnGridCellChange"></event>
911+ <event name="OnGridCellLeftClick">OnGridCellClick</event>
912+ <event name="OnGridCellLeftDClick"></event>
913+ <event name="OnGridCellRightClick"></event>
914+ <event name="OnGridCellRightDClick"></event>
915+ <event name="OnGridCmdCellChange"></event>
916+ <event name="OnGridCmdCellLeftClick"></event>
917+ <event name="OnGridCmdCellLeftDClick"></event>
918+ <event name="OnGridCmdCellRightClick"></event>
919+ <event name="OnGridCmdCellRightDClick"></event>
920+ <event name="OnGridCmdColSize"></event>
921+ <event name="OnGridCmdEditorCreated"></event>
922+ <event name="OnGridCmdEditorHidden"></event>
923+ <event name="OnGridCmdEditorShown"></event>
924+ <event name="OnGridCmdLabelLeftClick"></event>
925+ <event name="OnGridCmdLabelLeftDClick"></event>
926+ <event name="OnGridCmdLabelRightClick"></event>
927+ <event name="OnGridCmdLabelRightDClick"></event>
928+ <event name="OnGridCmdRangeSelect"></event>
929+ <event name="OnGridCmdRowSize"></event>
930+ <event name="OnGridCmdSelectCell"></event>
931+ <event name="OnGridColSize"></event>
932+ <event name="OnGridEditorCreated"></event>
933+ <event name="OnGridEditorHidden"></event>
934+ <event name="OnGridEditorShown"></event>
935+ <event name="OnGridLabelLeftClick"></event>
936+ <event name="OnGridLabelLeftDClick"></event>
937+ <event name="OnGridLabelRightClick"></event>
938+ <event name="OnGridLabelRightDClick"></event>
939+ <event name="OnGridRangeSelect"></event>
940+ <event name="OnGridRowSize"></event>
941+ <event name="OnGridSelectCell"></event>
942+ <event name="OnKeyDown"></event>
943+ <event name="OnKeyUp"></event>
944+ <event name="OnKillFocus"></event>
945+ <event name="OnLeaveWindow"></event>
946+ <event name="OnLeftDClick"></event>
947+ <event name="OnLeftDown"></event>
948+ <event name="OnLeftUp"></event>
949+ <event name="OnMiddleDClick"></event>
950+ <event name="OnMiddleDown"></event>
951+ <event name="OnMiddleUp"></event>
952+ <event name="OnMotion"></event>
953+ <event name="OnMouseEvents"></event>
954+ <event name="OnMouseWheel"></event>
955+ <event name="OnPaint"></event>
956+ <event name="OnRightDClick"></event>
957+ <event name="OnRightDown"></event>
958+ <event name="OnRightUp"></event>
959+ <event name="OnSetFocus"></event>
960+ <event name="OnSize"></event>
961+ <event name="OnUpdateUI"></event>
962+ </object>
963+ </object>
964+ </object>
965+ </object>
966+ <object class="sizeritem" expanded="1">
967+ <property name="border">0</property>
968+ <property name="flag">wxALIGN_RIGHT|wxALIGN_TOP</property>
969+ <property name="proportion">0</property>
970+ <object class="wxBoxSizer" expanded="1">
971+ <property name="minimum_size"></property>
972+ <property name="name">bButtonsSizer</property>
973+ <property name="orient">wxVERTICAL</property>
974+ <property name="permission">none</property>
975+ <object class="sizeritem" expanded="0">
976+ <property name="border">5</property>
977+ <property name="flag">wxALIGN_TOP|wxALL</property>
978+ <property name="proportion">0</property>
979+ <object class="wxBitmapButton" expanded="0">
980+ <property name="BottomDockable">1</property>
981+ <property name="LeftDockable">1</property>
982+ <property name="RightDockable">1</property>
983+ <property name="TopDockable">1</property>
984+ <property name="aui_layer"></property>
985+ <property name="aui_name"></property>
986+ <property name="aui_position"></property>
987+ <property name="aui_row"></property>
988+ <property name="best_size"></property>
989+ <property name="bg"></property>
990+ <property name="bitmap"></property>
991+ <property name="caption"></property>
992+ <property name="caption_visible">1</property>
993+ <property name="center_pane">0</property>
994+ <property name="close_button">1</property>
995+ <property name="context_help"></property>
996+ <property name="context_menu">1</property>
997+ <property name="current"></property>
998+ <property name="default">0</property>
999+ <property name="default_pane">0</property>
1000+ <property name="disabled"></property>
1001+ <property name="dock">Dock</property>
1002+ <property name="dock_fixed">0</property>
1003+ <property name="docking">Left</property>
1004+ <property name="enabled">1</property>
1005+ <property name="fg"></property>
1006+ <property name="floatable">1</property>
1007+ <property name="focus"></property>
1008+ <property name="font"></property>
1009+ <property name="gripper">0</property>
1010+ <property name="hidden">0</property>
1011+ <property name="id">wxID_ANY</property>
1012+ <property name="label">Move Up</property>
1013+ <property name="margins"></property>
1014+ <property name="markup">0</property>
1015+ <property name="max_size"></property>
1016+ <property name="maximize_button">0</property>
1017+ <property name="maximum_size"></property>
1018+ <property name="min_size"></property>
1019+ <property name="minimize_button">0</property>
1020+ <property name="minimum_size">32,32</property>
1021+ <property name="moveable">1</property>
1022+ <property name="name">m_moveUpButton</property>
1023+ <property name="pane_border">1</property>
1024+ <property name="pane_position"></property>
1025+ <property name="pane_size"></property>
1026+ <property name="permission">protected</property>
1027+ <property name="pin_button">1</property>
1028+ <property name="pos"></property>
1029+ <property name="position"></property>
1030+ <property name="pressed"></property>
1031+ <property name="resize">Resizable</property>
1032+ <property name="show">1</property>
1033+ <property name="size"></property>
1034+ <property name="style"></property>
1035+ <property name="subclass">; forward_declare</property>
1036+ <property name="toolbar_pane">0</property>
1037+ <property name="tooltip"></property>
1038+ <property name="validator_data_type"></property>
1039+ <property name="validator_style">wxFILTER_NONE</property>
1040+ <property name="validator_type">wxDefaultValidator</property>
1041+ <property name="validator_variable"></property>
1042+ <property name="window_extra_style"></property>
1043+ <property name="window_name"></property>
1044+ <property name="window_style"></property>
1045+ <event name="OnAux1DClick"></event>
1046+ <event name="OnAux1Down"></event>
1047+ <event name="OnAux1Up"></event>
1048+ <event name="OnAux2DClick"></event>
1049+ <event name="OnAux2Down"></event>
1050+ <event name="OnAux2Up"></event>
1051+ <event name="OnButtonClick">OnMoveUpButtonClick</event>
1052+ <event name="OnChar"></event>
1053+ <event name="OnCharHook"></event>
1054+ <event name="OnEnterWindow"></event>
1055+ <event name="OnEraseBackground"></event>
1056+ <event name="OnKeyDown"></event>
1057+ <event name="OnKeyUp"></event>
1058+ <event name="OnKillFocus"></event>
1059+ <event name="OnLeaveWindow"></event>
1060+ <event name="OnLeftDClick"></event>
1061+ <event name="OnLeftDown"></event>
1062+ <event name="OnLeftUp"></event>
1063+ <event name="OnMiddleDClick"></event>
1064+ <event name="OnMiddleDown"></event>
1065+ <event name="OnMiddleUp"></event>
1066+ <event name="OnMotion"></event>
1067+ <event name="OnMouseEvents"></event>
1068+ <event name="OnMouseWheel"></event>
1069+ <event name="OnPaint"></event>
1070+ <event name="OnRightDClick"></event>
1071+ <event name="OnRightDown"></event>
1072+ <event name="OnRightUp"></event>
1073+ <event name="OnSetFocus"></event>
1074+ <event name="OnSize"></event>
1075+ <event name="OnUpdateUI"></event>
1076+ </object>
1077+ </object>
1078+ <object class="sizeritem" expanded="1">
1079+ <property name="border">5</property>
1080+ <property name="flag">wxALL</property>
1081+ <property name="proportion">0</property>
1082+ <object class="wxBitmapButton" expanded="1">
1083+ <property name="BottomDockable">1</property>
1084+ <property name="LeftDockable">1</property>
1085+ <property name="RightDockable">1</property>
1086+ <property name="TopDockable">1</property>
1087+ <property name="aui_layer"></property>
1088+ <property name="aui_name"></property>
1089+ <property name="aui_position"></property>
1090+ <property name="aui_row"></property>
1091+ <property name="best_size"></property>
1092+ <property name="bg"></property>
1093+ <property name="bitmap"></property>
1094+ <property name="caption"></property>
1095+ <property name="caption_visible">1</property>
1096+ <property name="center_pane">0</property>
1097+ <property name="close_button">1</property>
1098+ <property name="context_help"></property>
1099+ <property name="context_menu">1</property>
1100+ <property name="current"></property>
1101+ <property name="default">0</property>
1102+ <property name="default_pane">0</property>
1103+ <property name="disabled"></property>
1104+ <property name="dock">Dock</property>
1105+ <property name="dock_fixed">0</property>
1106+ <property name="docking">Left</property>
1107+ <property name="enabled">1</property>
1108+ <property name="fg"></property>
1109+ <property name="floatable">1</property>
1110+ <property name="focus"></property>
1111+ <property name="font"></property>
1112+ <property name="gripper">0</property>
1113+ <property name="hidden">0</property>
1114+ <property name="id">wxID_ANY</property>
1115+ <property name="label">Move Down</property>
1116+ <property name="margins"></property>
1117+ <property name="markup">0</property>
1118+ <property name="max_size"></property>
1119+ <property name="maximize_button">0</property>
1120+ <property name="maximum_size"></property>
1121+ <property name="min_size"></property>
1122+ <property name="minimize_button">0</property>
1123+ <property name="minimum_size">32,32</property>
1124+ <property name="moveable">1</property>
1125+ <property name="name">m_moveDownButton</property>
1126+ <property name="pane_border">1</property>
1127+ <property name="pane_position"></property>
1128+ <property name="pane_size"></property>
1129+ <property name="permission">protected</property>
1130+ <property name="pin_button">1</property>
1131+ <property name="pos"></property>
1132+ <property name="position"></property>
1133+ <property name="pressed"></property>
1134+ <property name="resize">Resizable</property>
1135+ <property name="show">1</property>
1136+ <property name="size"></property>
1137+ <property name="style"></property>
1138+ <property name="subclass">; forward_declare</property>
1139+ <property name="toolbar_pane">0</property>
1140+ <property name="tooltip"></property>
1141+ <property name="validator_data_type"></property>
1142+ <property name="validator_style">wxFILTER_NONE</property>
1143+ <property name="validator_type">wxDefaultValidator</property>
1144+ <property name="validator_variable"></property>
1145+ <property name="window_extra_style"></property>
1146+ <property name="window_name"></property>
1147+ <property name="window_style"></property>
1148+ <event name="OnAux1DClick"></event>
1149+ <event name="OnAux1Down"></event>
1150+ <event name="OnAux1Up"></event>
1151+ <event name="OnAux2DClick"></event>
1152+ <event name="OnAux2Down"></event>
1153+ <event name="OnAux2Up"></event>
1154+ <event name="OnButtonClick">OnMoveDownButtonClick</event>
1155+ <event name="OnChar"></event>
1156+ <event name="OnCharHook"></event>
1157+ <event name="OnEnterWindow"></event>
1158+ <event name="OnEraseBackground"></event>
1159+ <event name="OnKeyDown"></event>
1160+ <event name="OnKeyUp"></event>
1161+ <event name="OnKillFocus"></event>
1162+ <event name="OnLeaveWindow"></event>
1163+ <event name="OnLeftDClick"></event>
1164+ <event name="OnLeftDown"></event>
1165+ <event name="OnLeftUp"></event>
1166+ <event name="OnMiddleDClick"></event>
1167+ <event name="OnMiddleDown"></event>
1168+ <event name="OnMiddleUp"></event>
1169+ <event name="OnMotion"></event>
1170+ <event name="OnMouseEvents"></event>
1171+ <event name="OnMouseWheel"></event>
1172+ <event name="OnPaint"></event>
1173+ <event name="OnRightDClick"></event>
1174+ <event name="OnRightDown"></event>
1175+ <event name="OnRightUp"></event>
1176+ <event name="OnSetFocus"></event>
1177+ <event name="OnSize"></event>
1178+ <event name="OnUpdateUI"></event>
1179+ </object>
1180+ </object>
1181+ <object class="sizeritem" expanded="1">
1182+ <property name="border">5</property>
1183+ <property name="flag">wxALL</property>
1184+ <property name="proportion">0</property>
1185+ <object class="wxBitmapButton" expanded="1">
1186+ <property name="BottomDockable">1</property>
1187+ <property name="LeftDockable">1</property>
1188+ <property name="RightDockable">1</property>
1189+ <property name="TopDockable">1</property>
1190+ <property name="aui_layer"></property>
1191+ <property name="aui_name"></property>
1192+ <property name="aui_position"></property>
1193+ <property name="aui_row"></property>
1194+ <property name="best_size"></property>
1195+ <property name="bg"></property>
1196+ <property name="bitmap"></property>
1197+ <property name="caption"></property>
1198+ <property name="caption_visible">1</property>
1199+ <property name="center_pane">0</property>
1200+ <property name="close_button">1</property>
1201+ <property name="context_help"></property>
1202+ <property name="context_menu">1</property>
1203+ <property name="current"></property>
1204+ <property name="default">0</property>
1205+ <property name="default_pane">0</property>
1206+ <property name="disabled"></property>
1207+ <property name="dock">Dock</property>
1208+ <property name="dock_fixed">0</property>
1209+ <property name="docking">Left</property>
1210+ <property name="enabled">1</property>
1211+ <property name="fg"></property>
1212+ <property name="floatable">1</property>
1213+ <property name="focus"></property>
1214+ <property name="font"></property>
1215+ <property name="gripper">0</property>
1216+ <property name="hidden">0</property>
1217+ <property name="id">wxID_ANY</property>
1218+ <property name="label">Reload Plugins</property>
1219+ <property name="margins"></property>
1220+ <property name="markup">0</property>
1221+ <property name="max_size"></property>
1222+ <property name="maximize_button">0</property>
1223+ <property name="maximum_size"></property>
1224+ <property name="min_size"></property>
1225+ <property name="minimize_button">0</property>
1226+ <property name="minimum_size">32,32</property>
1227+ <property name="moveable">1</property>
1228+ <property name="name">m_reloadButton</property>
1229+ <property name="pane_border">1</property>
1230+ <property name="pane_position"></property>
1231+ <property name="pane_size"></property>
1232+ <property name="permission">protected</property>
1233+ <property name="pin_button">1</property>
1234+ <property name="pos"></property>
1235+ <property name="position"></property>
1236+ <property name="pressed"></property>
1237+ <property name="resize">Resizable</property>
1238+ <property name="show">1</property>
1239+ <property name="size"></property>
1240+ <property name="style"></property>
1241+ <property name="subclass">; forward_declare</property>
1242+ <property name="toolbar_pane">0</property>
1243+ <property name="tooltip"></property>
1244+ <property name="validator_data_type"></property>
1245+ <property name="validator_style">wxFILTER_NONE</property>
1246+ <property name="validator_type">wxDefaultValidator</property>
1247+ <property name="validator_variable"></property>
1248+ <property name="window_extra_style"></property>
1249+ <property name="window_name"></property>
1250+ <property name="window_style"></property>
1251+ <event name="OnAux1DClick"></event>
1252+ <event name="OnAux1Down"></event>
1253+ <event name="OnAux1Up"></event>
1254+ <event name="OnAux2DClick"></event>
1255+ <event name="OnAux2Down"></event>
1256+ <event name="OnAux2Up"></event>
1257+ <event name="OnButtonClick">OnReloadButtonClick</event>
1258+ <event name="OnChar"></event>
1259+ <event name="OnCharHook"></event>
1260+ <event name="OnEnterWindow"></event>
1261+ <event name="OnEraseBackground"></event>
1262+ <event name="OnKeyDown"></event>
1263+ <event name="OnKeyUp"></event>
1264+ <event name="OnKillFocus"></event>
1265+ <event name="OnLeaveWindow"></event>
1266+ <event name="OnLeftDClick"></event>
1267+ <event name="OnLeftDown"></event>
1268+ <event name="OnLeftUp"></event>
1269+ <event name="OnMiddleDClick"></event>
1270+ <event name="OnMiddleDown"></event>
1271+ <event name="OnMiddleUp"></event>
1272+ <event name="OnMotion"></event>
1273+ <event name="OnMouseEvents"></event>
1274+ <event name="OnMouseWheel"></event>
1275+ <event name="OnPaint"></event>
1276+ <event name="OnRightDClick"></event>
1277+ <event name="OnRightDown"></event>
1278+ <event name="OnRightUp"></event>
1279+ <event name="OnSetFocus"></event>
1280+ <event name="OnSize"></event>
1281+ <event name="OnUpdateUI"></event>
1282+ </object>
1283+ </object>
1284+ </object>
1285+ </object>
1286+ </object>
1287+ </object>
1288+ </object>
1289+</wxFormBuilder_Project>
1290diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins_base.h b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.h
1291new file mode 100644
1292index 0000000..8766d0c
1293--- /dev/null
1294+++ b/pcbnew/dialogs/panel_pcbnew_action_plugins_base.h
1295@@ -0,0 +1,58 @@
1296+///////////////////////////////////////////////////////////////////////////
1297+// C++ code generated with wxFormBuilder (version Jul 11 2018)
1298+// http://www.wxformbuilder.org/
1299+//
1300+// PLEASE DO *NOT* EDIT THIS FILE!
1301+///////////////////////////////////////////////////////////////////////////
1302+
1303+#ifndef __PANEL_PCBNEW_ACTION_PLUGINS_BASE_H__
1304+#define __PANEL_PCBNEW_ACTION_PLUGINS_BASE_H__
1305+
1306+#include <wx/artprov.h>
1307+#include <wx/xrc/xmlres.h>
1308+class WX_GRID;
1309+
1310+#include <wx/colour.h>
1311+#include <wx/settings.h>
1312+#include <wx/string.h>
1313+#include <wx/font.h>
1314+#include <wx/grid.h>
1315+#include <wx/gdicmn.h>
1316+#include <wx/sizer.h>
1317+#include <wx/bmpbuttn.h>
1318+#include <wx/bitmap.h>
1319+#include <wx/image.h>
1320+#include <wx/icon.h>
1321+#include <wx/button.h>
1322+#include <wx/panel.h>
1323+
1324+///////////////////////////////////////////////////////////////////////////
1325+
1326+///////////////////////////////////////////////////////////////////////////////
1327+/// Class PANEL_PCBNEW_ACTION_PLUGINS_BASE
1328+///////////////////////////////////////////////////////////////////////////////
1329+class PANEL_PCBNEW_ACTION_PLUGINS_BASE : public wxPanel
1330+{
1331+ private:
1332+
1333+ protected:
1334+ WX_GRID* m_grid;
1335+ wxBitmapButton* m_moveUpButton;
1336+ wxBitmapButton* m_moveDownButton;
1337+ wxBitmapButton* m_reloadButton;
1338+
1339+ // Virtual event handlers, overide them in your derived class
1340+ virtual void OnGridCellClick( wxGridEvent& event ) { event.Skip(); }
1341+ virtual void OnMoveUpButtonClick( wxCommandEvent& event ) { event.Skip(); }
1342+ virtual void OnMoveDownButtonClick( wxCommandEvent& event ) { event.Skip(); }
1343+ virtual void OnReloadButtonClick( wxCommandEvent& event ) { event.Skip(); }
1344+
1345+
1346+ public:
1347+
1348+ PANEL_PCBNEW_ACTION_PLUGINS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 485,200 ), long style = wxTAB_TRAVERSAL );
1349+ ~PANEL_PCBNEW_ACTION_PLUGINS_BASE();
1350+
1351+};
1352+
1353+#endif //__PANEL_PCBNEW_ACTION_PLUGINS_BASE_H__
1354diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp
1355index 9149d4b..49f20b8 100644
1356--- a/pcbnew/pcb_edit_frame.cpp
1357+++ b/pcbnew/pcb_edit_frame.cpp
1358@@ -1249,6 +1249,8 @@ void PCB_EDIT_FRAME::PythonPluginsReload()
1359 // Action plugins can be modified, therefore the plugins menu
1360 // must be updated:
1361 RebuildActionPluginMenus();
1362+ // Recreate top toolbar to add action plugin buttons
1363+ ReCreateHToolbar();
1364 #endif
1365 #endif
1366 }
1367diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h
1368index 4179353..62c4dd4 100644
1369--- a/pcbnew/pcb_edit_frame.h
1370+++ b/pcbnew/pcb_edit_frame.h
1371@@ -25,13 +25,14 @@
1372 #define WXPCB_STRUCT_H_
1373
1374 #include <unordered_map>
1375+#include <map>
1376 #include "pcb_base_edit_frame.h"
1377 #include "config_params.h"
1378 #include "undo_redo_container.h"
1379 #include "zones.h"
1380
1381-
1382 /* Forward declarations of classes. */
1383+class ACTION_PLUGIN;
1384 class PCB_SCREEN;
1385 class BOARD;
1386 class BOARD_COMMIT;
1387@@ -122,6 +123,12 @@ protected:
1388 void RebuildActionPluginMenus();
1389
1390 /**
1391+ * Function AddActionPluginTools
1392+ * Append action plugin buttons to main toolbar
1393+ */
1394+ void AddActionPluginTools();
1395+
1396+ /**
1397 * Function OnActionPlugin
1398 * Launched by the menu when an action is called
1399 * @param aEvent sent by wx
1400@@ -379,6 +386,36 @@ public:
1401 // Configurations:
1402 void Process_Config( wxCommandEvent& event );
1403
1404+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1405+
1406+ /**
1407+ * Function SetActionPluginSettings
1408+ * Set a set of plugins that have visible buttons on toolbar
1409+ * Plugins are identified by their module path
1410+ */
1411+ void SetActionPluginSettings( const std::vector< std::pair<wxString, wxString> >& aPluginsWithButtons );
1412+
1413+ /**
1414+ * Function GetActionPluginSettings
1415+ * Get a set of plugins that have visible buttons on toolbar
1416+ */
1417+ std::vector< std::pair<wxString, wxString> > GetActionPluginSettings();
1418+
1419+ /**
1420+ * Function GetActionPluginButtonVisible
1421+ * Returns true if button visibility action plugin setting was set to true
1422+ * or it is unset and plugin defaults to true.
1423+ */
1424+ bool GetActionPluginButtonVisible( const wxString& aPluginPath, bool aPluginDefault );
1425+
1426+ /**
1427+ * Function GetOrderedActionPlugins
1428+ * Returns ordered list of plugins in sequence in which they should appear on toolbar or in settings
1429+ */
1430+ std::vector<ACTION_PLUGIN*> GetOrderedActionPlugins();
1431+
1432+#endif
1433+
1434 /**
1435 * Function GetProjectFileParameters
1436 * returns a project file parameter list for Pcbnew.
1437diff --git a/pcbnew/pcb_general_settings.cpp b/pcbnew/pcb_general_settings.cpp
1438index a8c70cd..76d3867 100644
1439--- a/pcbnew/pcb_general_settings.cpp
1440+++ b/pcbnew/pcb_general_settings.cpp
1441@@ -22,6 +22,7 @@
1442 */
1443
1444 #include <pcb_general_settings.h>
1445+#include <wx/tokenzr.h>
1446
1447 PCB_GENERAL_SETTINGS::PCB_GENERAL_SETTINGS( FRAME_T aFrameType )
1448 : m_frameType( aFrameType ), m_colorsSettings( aFrameType )
1449@@ -54,6 +55,32 @@ PCB_GENERAL_SETTINGS::PCB_GENERAL_SETTINGS( FRAME_T aFrameType )
1450 void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
1451 {
1452 m_colorsSettings.Load( aCfg );
1453+
1454+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1455+
1456+ m_pluginSettings.clear();
1457+
1458+ wxString pluginSettings = aCfg->Read( "ActionPluginButtons" );
1459+
1460+ wxStringTokenizer pluginSettingsTokenizer = wxStringTokenizer( pluginSettings, ";" );
1461+
1462+ while( pluginSettingsTokenizer.HasMoreTokens() )
1463+ {
1464+ wxString plugin = pluginSettingsTokenizer.GetNextToken();
1465+ wxStringTokenizer pluginTokenizer = wxStringTokenizer( plugin, "=" );
1466+
1467+ if ( pluginTokenizer.CountTokens() != 2 )
1468+ {
1469+ // Bad config
1470+ continue;
1471+ }
1472+
1473+ plugin = pluginTokenizer.GetNextToken();
1474+ m_pluginSettings.push_back( std::make_pair( plugin, pluginTokenizer.GetNextToken() ) );
1475+ }
1476+
1477+#endif
1478+
1479 SETTINGS::Load( aCfg );
1480 }
1481
1482@@ -61,6 +88,24 @@ void PCB_GENERAL_SETTINGS::Load( wxConfigBase* aCfg )
1483 void PCB_GENERAL_SETTINGS::Save( wxConfigBase* aCfg )
1484 {
1485 m_colorsSettings.Save( aCfg );
1486+
1487+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1488+
1489+ wxString pluginSettings;
1490+
1491+ for( auto const& entry : m_pluginSettings )
1492+ {
1493+ if( !pluginSettings.IsEmpty() )
1494+ {
1495+ pluginSettings = pluginSettings + wxT( ";" );
1496+ }
1497+ pluginSettings = pluginSettings + entry.first + wxT( "=" ) + entry.second;
1498+ }
1499+
1500+ aCfg->Write( "ActionPluginButtons" , pluginSettings );
1501+
1502+#endif
1503+
1504 SETTINGS::Save( aCfg );
1505 }
1506
1507diff --git a/pcbnew/pcb_general_settings.h b/pcbnew/pcb_general_settings.h
1508index bc8f953..fbcbe90 100644
1509--- a/pcbnew/pcb_general_settings.h
1510+++ b/pcbnew/pcb_general_settings.h
1511@@ -25,6 +25,7 @@
1512 #define __PCBNEW_GENERAL_SETTINGS_H
1513
1514 #include <colors_design_settings.h>
1515+#include <vector>
1516
1517 class wxConfigBase;
1518 class wxString;
1519@@ -65,6 +66,10 @@ public:
1520 MAGNETIC_PAD_OPTION_VALUES m_magneticPads = CAPTURE_CURSOR_IN_TRACK_TOOL;
1521 MAGNETIC_PAD_OPTION_VALUES m_magneticTracks = CAPTURE_CURSOR_IN_TRACK_TOOL;
1522
1523+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1524+ std::vector< std::pair<wxString, wxString> > m_pluginSettings; // Settings for action plugins
1525+#endif
1526+
1527 protected:
1528 const FRAME_T m_frameType;
1529 COLORS_DESIGN_SETTINGS m_colorsSettings;
1530diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp
1531index ae164fd..b6025a5 100644
1532--- a/pcbnew/pcbnew_config.cpp
1533+++ b/pcbnew/pcbnew_config.cpp
1534@@ -45,6 +45,7 @@
1535 #include <panel_hotkeys_editor.h>
1536 #include <panel_pcbnew_settings.h>
1537 #include <panel_pcbnew_display_options.h>
1538+#include <panel_pcbnew_action_plugins.h>
1539 #include <fp_lib_table.h>
1540 #include <worksheet_shape_builder.h>
1541 #include <class_board.h>
1542@@ -97,6 +98,9 @@ void PCB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent )
1543
1544 book->AddPage( new PANEL_PCBNEW_SETTINGS( this, aParent ), _( "Pcbnew" ) );
1545 book->AddSubPage( new PANEL_PCBNEW_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
1546+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1547+ book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
1548+#endif
1549 }
1550
1551
1552diff --git a/pcbnew/swig/pcbnew_action_plugins.cpp b/pcbnew/swig/pcbnew_action_plugins.cpp
1553index 4fb232e..12e0906 100644
1554--- a/pcbnew/swig/pcbnew_action_plugins.cpp
1555+++ b/pcbnew/swig/pcbnew_action_plugins.cpp
1556@@ -140,6 +140,32 @@ wxString PYTHON_ACTION_PLUGIN::GetDescription()
1557 }
1558
1559
1560+bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton()
1561+{
1562+ PyLOCK lock;
1563+
1564+ PyObject* result = CallMethod( "GetShowToolbarButton");
1565+
1566+ return PyObject_IsTrue(result);
1567+}
1568+
1569+
1570+wxString PYTHON_ACTION_PLUGIN::GetIconFileName()
1571+{
1572+ PyLOCK lock;
1573+
1574+ return CallRetStrMethod( "GetIconFileName" );
1575+}
1576+
1577+
1578+wxString PYTHON_ACTION_PLUGIN::GetPluginPath()
1579+{
1580+ PyLOCK lock;
1581+
1582+ return CallRetStrMethod( "GetPluginPath" );
1583+}
1584+
1585+
1586 void PYTHON_ACTION_PLUGIN::Run()
1587 {
1588 PyLOCK lock;
1589@@ -177,6 +203,12 @@ void PCB_EDIT_FRAME::OnActionPlugin( wxCommandEvent& aEvent )
1590
1591 ACTION_PLUGIN* actionPlugin = ACTION_PLUGINS::GetActionByMenu( id );
1592
1593+ if ( !actionPlugin )
1594+ {
1595+ // Try looking by button
1596+ actionPlugin = ACTION_PLUGINS::GetActionByButton( id );
1597+ }
1598+
1599 if( actionPlugin )
1600 {
1601 PICKED_ITEMS_LIST itemsList;
1602@@ -416,19 +448,28 @@ void PCB_EDIT_FRAME::RebuildActionPluginMenus()
1603 for( int ii = 0; ii < ACTION_PLUGINS::GetActionsCount(); ii++ )
1604 {
1605 wxMenuItem* item;
1606+ ACTION_PLUGIN* ap = ACTION_PLUGINS::GetAction( ii );
1607+ const wxBitmap& bitmap = ap->iconBitmap.IsOk() ? ap->iconBitmap : KiBitmap( hammer_xpm );
1608
1609 if( ii < (int) available_menus.size() )
1610 {
1611 item = available_menus[ii];
1612- item->SetItemLabel( ACTION_PLUGINS::GetAction( ii )->GetName() );
1613- item->SetHelp( ACTION_PLUGINS::GetAction( ii )->GetDescription() );
1614+ item->SetItemLabel( ap->GetName() );
1615+ item->SetHelp( ap->GetDescription() );
1616+
1617+ // On windows we need to set "unchecked" bitmap
1618+#if defined(__WXMSW__)
1619+ item->SetBitmap( bitmap, false );
1620+#else
1621+ item->SetBitmap( bitmap );
1622+#endif
1623 }
1624 else
1625 {
1626 item = AddMenuItem( actionMenu, wxID_ANY,
1627- ACTION_PLUGINS::GetAction( ii )->GetName(),
1628- ACTION_PLUGINS::GetAction( ii )->GetDescription(),
1629- KiBitmap( hammer_xpm ) );
1630+ ap->GetName(),
1631+ ap->GetDescription(),
1632+ bitmap );
1633
1634 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1635 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &
1636@@ -440,4 +481,104 @@ void PCB_EDIT_FRAME::RebuildActionPluginMenus()
1637 }
1638
1639
1640+void PCB_EDIT_FRAME::AddActionPluginTools()
1641+{
1642+ bool need_separator = true;
1643+ const auto& orderedPlugins = GetOrderedActionPlugins();
1644+
1645+ for( const auto& ap : orderedPlugins )
1646+ {
1647+ if( GetActionPluginButtonVisible( ap->GetPluginPath(), ap->GetShowToolbarButton() ) )
1648+ {
1649+
1650+ if ( need_separator )
1651+ {
1652+ KiScaledSeparator( m_mainToolBar, this );
1653+ need_separator = false;
1654+ }
1655+
1656+ // Add button
1657+ wxBitmap bitmap;
1658+
1659+ if ( ap->iconBitmap.IsOk() )
1660+ bitmap = KiScaledBitmap( ap->iconBitmap, this );
1661+ else
1662+ bitmap = KiScaledBitmap( hammer_xpm, this );
1663+
1664+ wxAuiToolBarItem* button = m_mainToolBar->AddTool(
1665+ wxID_ANY, wxEmptyString, bitmap, ap->GetName() );
1666+
1667+ Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1668+ (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &
1669+ PCB_EDIT_FRAME::OnActionPlugin );
1670+
1671+ // Link action plugin to button
1672+ ACTION_PLUGINS::SetActionButton( ap, button->GetId() );
1673+ }
1674+ }
1675+}
1676+
1677+
1678+void PCB_EDIT_FRAME::SetActionPluginSettings( const std::vector< std::pair<wxString, wxString> >& aPluginSettings )
1679+{
1680+ m_configSettings.m_pluginSettings = aPluginSettings;
1681+ ReCreateHToolbar();
1682+}
1683+
1684+
1685+std::vector< std::pair<wxString, wxString> > PCB_EDIT_FRAME::GetActionPluginSettings()
1686+{
1687+ return m_configSettings.m_pluginSettings;
1688+}
1689+
1690+
1691+std::vector<ACTION_PLUGIN*> PCB_EDIT_FRAME::GetOrderedActionPlugins()
1692+{
1693+ std::vector<ACTION_PLUGIN*> orderedPlugins;
1694+ const auto& pluginSettings = GetActionPluginSettings();
1695+
1696+ // First add plugins that have entries in settings
1697+ for( size_t ii = 0; ii < pluginSettings.size(); ii++ )
1698+ {
1699+ for( int jj = 0; jj < ACTION_PLUGINS::GetActionsCount(); jj++ )
1700+ {
1701+ if( ACTION_PLUGINS::GetAction( jj )->GetPluginPath() == pluginSettings[ii].first )
1702+ orderedPlugins.push_back( ACTION_PLUGINS::GetAction( jj ) );
1703+ }
1704+ }
1705+
1706+ // Now append new plugins that have not been configured yet
1707+ for( int ii = 0; ii < ACTION_PLUGINS::GetActionsCount(); ii++ )
1708+ {
1709+ bool found = false;
1710+
1711+ for( size_t jj = 0; jj < orderedPlugins.size(); jj++ )
1712+ {
1713+ if( ACTION_PLUGINS::GetAction( ii ) == orderedPlugins[jj] )
1714+ found = true;
1715+ }
1716+
1717+ if ( !found )
1718+ orderedPlugins.push_back( ACTION_PLUGINS::GetAction( ii ) );
1719+ }
1720+
1721+ return orderedPlugins;
1722+}
1723+
1724+
1725+bool PCB_EDIT_FRAME::GetActionPluginButtonVisible( const wxString& aPluginPath, bool aPluginDefault )
1726+{
1727+ auto& settings = m_configSettings.m_pluginSettings;
1728+
1729+ for(const auto& entry : settings )
1730+ {
1731+ if (entry.first == aPluginPath )
1732+ return entry.second == wxT( "Visible" );
1733+ }
1734+
1735+ // Plugin is not in settings, return default.
1736+ return aPluginDefault;
1737+}
1738+
1739+
1740 #endif
1741diff --git a/pcbnew/swig/pcbnew_action_plugins.h b/pcbnew/swig/pcbnew_action_plugins.h
1742index 08dfa14..a1d6d9f 100644
1743--- a/pcbnew/swig/pcbnew_action_plugins.h
1744+++ b/pcbnew/swig/pcbnew_action_plugins.h
1745@@ -47,6 +47,9 @@ public:
1746 wxString GetCategoryName() override;
1747 wxString GetName() override;
1748 wxString GetDescription() override;
1749+ bool GetShowToolbarButton() override;
1750+ wxString GetIconFileName() override;
1751+ wxString GetPluginPath() override;
1752 void Run() override;
1753 void* GetObject() override;
1754 };
1755diff --git a/pcbnew/tool_pcb_editor.cpp b/pcbnew/tool_pcb_editor.cpp
1756index 66b6223..b5c64c3 100644
1757--- a/pcbnew/tool_pcb_editor.cpp
1758+++ b/pcbnew/tool_pcb_editor.cpp
1759@@ -321,6 +321,10 @@ void PCB_EDIT_FRAME::ReCreateHToolbar()
1760 m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
1761 KiScaledBitmap( py_script_xpm, this ),
1762 _( "Show/Hide the Python Scripting console" ), wxITEM_CHECK );
1763+
1764+#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
1765+ AddActionPluginTools();
1766+#endif
1767 }
1768 #endif
1769
1770diff --git a/scripting/kicadplugins.i b/scripting/kicadplugins.i
1771index 8c1781d..fb92f1f 100644
1772--- a/scripting/kicadplugins.i
1773+++ b/scripting/kicadplugins.i
1774@@ -260,7 +260,7 @@ def LoadPlugins(bundlepath=None):
1775 if module == '__init__.py' or module[-3:] != '.py':
1776 continue
1777
1778- LoadOnePlugin(plugins_dir, module);
1779+ LoadOnePlugin(plugins_dir, module)
1780
1781
1782 class KiCadPlugin:
1783@@ -268,6 +268,9 @@ class KiCadPlugin:
1784 pass
1785
1786 def register(self):
1787+ import inspect
1788+ import os
1789+
1790 if isinstance(self,FilePlugin):
1791 pass # register to file plugins in C++
1792
1793@@ -276,6 +279,13 @@ class KiCadPlugin:
1794 return
1795
1796 if isinstance(self,ActionPlugin):
1797+ """
1798+ Get path to .py or .pyc that has definition of plugin class.
1799+ If path is binary but source also exists, assume definition is in source.
1800+ """
1801+ self.__plugin_path = inspect.getfile(self.__class__)
1802+ if self.__plugin_path.endswith('.pyc') and os.path.isfile(self.__plugin_path[:-1]):
1803+ self.__plugin_path = self.__plugin_path[:-1]
1804 PYTHON_ACTION_PLUGINS.register_action(self)
1805 return
1806
1807@@ -295,6 +305,9 @@ class KiCadPlugin:
1808
1809 return
1810
1811+ def GetPluginPath( self ):
1812+ return self.__plugin_path
1813+
1814
1815 class FilePlugin(KiCadPlugin):
1816 def __init__(self):
1817@@ -633,6 +646,8 @@ class FootprintWizardPlugin(KiCadPlugin, object):
1818 class ActionPlugin(KiCadPlugin, object):
1819 def __init__( self ):
1820 KiCadPlugin.__init__( self )
1821+ self.icon_file_name = ""
1822+ self.show_toolbar_button = False
1823 self.defaults()
1824
1825 def defaults( self ):
1826@@ -649,6 +664,12 @@ class ActionPlugin(KiCadPlugin, object):
1827 def GetDescription( self ):
1828 return self.description
1829
1830+ def GetShowToolbarButton( self ):
1831+ return self.show_toolbar_button
1832+
1833+ def GetIconFileName( self ):
1834+ return self.icon_file_name
1835+
1836 def Run(self):
1837 return
1838

Subscribers

People subscribed via source and target branches

to status/vote changes: