Plugin Question

I started fooling around with Plugin’s and used the “Simple_Example” posted on the Kicad-source-mirror.

The plugin Correctly shows up in the Tools>External Plugins field.

Selecting it to run produces no problems.

However, the plugin is supposed to produce a “Hello World” but I see nothing (not at bottom of Window or anywhere…)

Where is it going be be displayed???

Here’s the snippet of code (the .py is placed in only one plugin Dir location):


import pcbnew
class SimplePlugin(pcbnew.ActionPlugin):
def defaults(self):
self.name = “Plugin Name as shown in Pcbnew: Tools->External Plugins”
self.category = “A descriptive category name”
self.description = “A description of the plugin and what it does”
def Run(self):
# The entry function of the plugin that is executed on user action
print(“Hello World”)
SimplePlugin().register() # Instantiate and register to Pcbnew

The python interpreter prints it to the default output, and because there’s no any console or something like that, you can’t see anything. It’s just a very simple example indeed. If you want to see a GUI you have to create it with wxWidgets. See some interactive plugin made by someone if you need and example for that.

Thank you. Basically that’s what I thought…

What I’ve been doing for this is opening a file in the project directory and making sure I write all my output into the file. (Like this: https://github.com/ian-ross/kicad-plugins/blob/main/SchematicPositionsToLayout.py#L146-L153) It’s no way as nice as building a proper GUI, but it’s useful for debugging and post-plugin-run checking, if it’s the right kind of plugin for that.

1 Like

Thanks. I’ll give it try (I always prefer to write to a console so, I dig up some other approaches, too. Including a GUI frame.

I don’t like Python (much prefer Java…)

If you are on linux or mac then launching kicad or pcbnew from command line will capture output of your plugins in the terminal you launched it from.
If you are on windows you can launch your plugin from pcbnew’s scripting console, output will show up there.

1 Like

KiCommand starts a GUI window with an input textbox and an output multiline text box. I used a common tool to generate the window design and that tool allows you to output a Python class. Then within KiCommand, I import that file, and instantiate the class. The write to the output textbox throughout the program. If you decide to peruse the source code and have any questions, let me know.

Im sure a modern review of the KiCommand code would reveal some places where a rewrite is in order.

A couple of things to watch out for: in some cases a wx version mismatch might require small hand modifications of the gui class, and startup of the plugin’s gui can be tricky since KiCAD’s window startup is not really defined very well, and the window you want to be the parent of your created window might not exist until after a certain point in startup, perhaps after your plugin code executes.

Thanks everyone - I appreciate your responses.
Not sure if I want to bother going beyond a ‘just testing it out’ effort.
As with all programming languages, it’s about the syntax and, for me, having a ‘purpose’ (meaning, ‘what do I want the code to do?’).

Kicad does everything I need it to do for making real PCB’s so, it’s a stretch to find a ‘purpose’ beyond my ‘programmers’ curiosity… And, though I’ve done some Python programming and checked out the usual GUI making/tools, I gravitate back to Java (and Eclipse with Window Builder) because I can do it in my sleep… I seldom use C/C++ except for coding Arduino’s and Atmel & PIC chips…

In fact, having dialed down to what I really need & use, I have bags of PIC chips and some programmers that I’d give away to anyone that would use them…

Thanks again