Skip to content

Experimental support for KiCad 9 kicad-python#128

Draft
mairas wants to merge 8 commits intogregdavill:mainfrom
mairas:kipy
Draft

Experimental support for KiCad 9 kicad-python#128
mairas wants to merge 8 commits intogregdavill:mainfrom
mairas:kipy

Conversation

@mairas
Copy link
Copy Markdown
Contributor

@mairas mairas commented Feb 7, 2025

Hi,

KiBuzzard was always crashing on KiCad 9 nightlies when I tried to edit any created labels. I assumed it was a KiBuzzard issue and instead of trying to debug the SWIG interface, I decided to try the new IPC API and the kicad-python bindings. Turns out, I was out for an adventure.

This PR, which should NOT be merged to main as-is, contains my experimental KiBuzzard version using kicad-python. It somewhat works, but since you can't initiate a clipboard paste or an interactive place operation from the new API, I just copy the footprint to the clipboard instead. For updates, the old footprint is removed but you still need to initiate pasting manually to replace it with the updated one.

Here are rough steps to get the PR branch version working.

Prerequisites: KiCad 9 nightly (I don't think -rc2 would work but not sure about that).

Clone kicad-python main branch and build into a wheel (poetry build).

Clone this PR to ${KICAD_DOCUMENTS_HOME}/9.0/plugins. Replace the kicad-python path in requirements.txt with the wheel you created (should be in the dist directory of kicad-python sources.

To see what's going on, you might want to enable tracing for the API:

export KICAD_ALLOC_CONSOLE=1
export KICAD_ENABLE_WXTRACE=1
export WXTRACE=KICAD_API

Then launch KiCad from the command line. On Linux the process is obvious, on MacOS, you need to run the binary inside the .app directory, for example:

/Applications/KiCad\ 2025-02-06/KiCad.app/Contents/MacOS/kicad

Open a project and start PCB Editor. With a bit of luck, you'll have a KiBuzzard icon on the toolbar. Click on it. KiBuzzard will start as a separate process. On a Mac, the KiBuzzard window is always behind the PCB Editor window and isn't visible in Mission Control, but you can switch to it via the Dock. (To make this more bearable, I created a Hammerspoon snippet that raises the window automagically when it's created.))

At this point, you should have a plain old KiBuzzard dialog window. Create your label and click OK. This will close the dialog. You will need to paste the created label footprint manually on the PCB.

Editing works as before, almost: select a KiBuzzard label and click on the icon. KiBuzzard will open (behind the main window) and will have the label data preloaded. Make your changes and press OK. The old label is removed and the new one is placed on the clipboard. You will need to paste it yourself!

As of today, the PCB Editor will tend to crash soon after any footprint is pasted, so whenever you make an update, save, close and restart PCB Editor. If you don't, KiCad will do this for you, taking also the schematic editor down... A fix has been committed, so in the next nightly (after 2025-02-26), the issue might be fixed.

NOTE: My problems with the stock KiBuzzard are likely due to the same issue linked in the previous paragraph. Assuming this is the case, the stock version should work just fine and there is no reason to actually use this PR version. However, if kicad-python improves over time, my dabblings could be used as a basis for an updated KiBuzzard.

@gregdavill
Copy link
Copy Markdown
Owner

Thanks for the ground-work in testing this out. It has been announced that the SWIG interface will be deprecated, but not when that will happen. KiCad 10?/11? So it's very useful to have an example of the state of the new plugin system.

Part of the rationale behind bundling the dependencies was so the entire plugin could be installed via the PCM.

I'll need to dig through the IPC API, If they're not supporting modal dialogs we could switch the KiBuzzard logic to be it's own, and not close when placing/updating a label.

@mairas
Copy link
Copy Markdown
Contributor Author

mairas commented Mar 6, 2025

I believe the stated timeline for the SWIG interface removal is in v10, but given the rough state of the new API, I really don't believe it'll happen before KiCad 11. That's my speculation, though.

At the moment, some of the API calls critical for KiBuzzard are completely unimplemented. In particular, you can't convert S-expression footprints to footprint objects, making the current KiBuzzard label updates impossible to achieve. You could rewrite the whole code to create native graphical objects instead of S-expressions, but... yeah. I raised an issue about the broken endpoint but it got tagged as v10...

The new API is conceptually quite different from the old one. As the name states, it's an Inter-Process Communication API, and any plugins will run in separate processes. Hence, they're not limited to using the bundled Python interpreter, and they can also install dependencies freely. Also any windows or dialogs drawn by the plugin are inde The new model is quite nice for development because you can even run API snippets in a Jupyter notebook. On the other hand, since any running plugins are independent processes, it makes things quite messy from windowing PoV. Any windows or dialogs drawn by a plugin are independent of the KiCad app windows. The dialog window can hide below the main app window (and on a Mac, it indeed does, unless there's a workaround).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants