KiCad plugin debug

Hi,
I’m trying to wrote an action plugin for kicad. By hacking around another plugin, I have something that kind of work.
I would like to use pycharm to debug my plugin.
I’ve been able to point pycharm to the kicad python interpreter.

To run the plugin, I’m supposed that I must call it from the main. But How to load the board ? and how to get the frame for displaying a windows in WX ?

Is there an example somewhere of a plugin with the necessary code to support the debugger ?

There is no way to debug action plugin when it’s running inside kicad. Because there is no python interpreter running as any python debugger would expect, instead python code is executed from python c bindings so it runs as part of kicad executable.

What you can do is

  1. Universal “printf debug” method. I.e. add logging statements in critical points of your plugin to understand what is state of the code, what parts are reachable, etc. In case of kicad plugins I usually use wx.MessageBox() to pop a window with the log message because stdout is not visible on windows. If you are on linux/mac simple print should work fine.
  2. Add CLI entry point to your plugin essentially executing it as a simple script. For most plugins that are not interactive and just need to read/write the board once this works fine. Pass the board to the script as a command line argument and read it using pcbnew.LoadBoard().
    Then you can debug your CLI script as usual and with it the plugin code.

I use both methods for InteractiveHtmlBom plugin.

You don’t need one, just create a dialog/window and call Show()/ShowModal() on it. It will not have correct parent relationship to the pcbnew window but it doesn’t cause issues.
If your question is about how to create a dialog in the first place, well thats a long topic and you should read wxpython docs and examples. There is also wxFormBuilder that is frequently used to generate code for the form itself so that only thing you have to do is implement handlers for the events. Saves time on hand crafting all the buttons, panels, sizers etc.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.