Learning to develop in KiCad (1) - Add a dialog

All my series of “Learning to Develop KiCad” posts are listed in FAQ


Here is translation from my Chinese article.
I didn’t find a proper platform to share my articles in English. I tried Medium, but I found it may not be better than KiCad forum.

I’m reading current length tuning implementation inside KiCad, and want to try to improve it. But first, I need to show a dialog, something similar to Net Inspector, but functionality like Plugin KiCad Length Matching. The dev doc for KiCad has only samples about PCB TOOLS, too little information to start dev for KiCad. So I wrote articles while I am doing experiments on dev for KiCad, to leave some more information about it.

First, I need to add a dialog like this:

As you know, the KiCad is based on wxWidgets, and all its dialog is designed with wxFormBuilder, which saves design file as .fbp format, and generate _base.h/.cpp files / classes.

After started wxFormBuilder, it created an empty project by default. Change its name and other properties like this:
640 (2)
and change properties for the project like this
640 (3)

Add a “Dialog” in Forms tab

Change properties of the Dialog

And we make the dialog as how Net Inspector does: who is derived from DIALOG_SHIM

Add more controls:

And change their default properties (especially their names)
640 (8)

Save the project under KiCad Source Code/pcbnew/dialogs/ and click the left corner GEAR button to generate C++ code
640 (9)

Now, there are three files here
640 (10)

Next, we need to define our customized subclass DIALOG_LENGTH_TUNING like this:


 * License is omitted
#pragma once

#include <board.h>
#include <optional>
#include <dialog_length_tuning_base.h>

class BOARD;
class CN_ITEM;
class PCB_TRACK;

 * Event sent to parent when dialog is mode-less.



 * License is omitted

#include <dialog_length_tuning.h>
#include <pcb_edit_frame.h>




Modify current KiCad Source Code, to open our new dialog in UI:


640 (11)


640 (12)


640 (15)
640 (16)


640 (18)


640 (19)


640 (20)


640 (21)


if all goes well, and you build kicad now, and run it, there will be a new item named Length Tuning, inside Inspect menu, and click it then shows:

All the code is here

Hope this could be helpful for you.


Hi @ sprhawk
Interesting timing that you post this now as I have spent the last week looking into wxwidgets and wxformbuilder as I wish to learn a new gui and dig deeper into c++. Being a hardware and embedded C guy, I can say that desktop software gets overwhelming pretty quickly, so it was nice to see another tutorial of sorts. I am not doing this to work on kicad, just to see if I can get a cross-platform gui running for talking to my embedded devices. I had previously used python and pysimplegui/numpy/scipy with a usb-hid interface and got some good fft/plot performance on linux (and crappy performance on win). Now I am trying to do something similar with a kinda-fast serial data stream and a different gui using C or C++ instead of python. I am unsure whether I can figure out the wxwidgets event loop to put data-receive/crunching code in place and plot in realtime or not as it does not seem to be designed for that use-case. I looked at dearimgui and some other approaches, but that all looks to be a steep learning curve.
Anyway, thanks for posting as I enjoyed reading through it!

@teletypeguy I love wxFormBuilder (especially the recent version 4.0).

I use it to build my GUI’s for Kicad Plugin’s. I do them with Python but, the builder has C++, too and can place Code into the Builder’s panel…

Have Fun!

C# + Avalonia UI + Oxyplot

The overhead and complexity of C/C++ isn’t worth it compared to a memory-safe language with a massive ecosystem of libraries served via package manager.

wxWidgets also isn’t built for plotting. Our spice simulator is a big hackjob and we do aim to replace the plotting one day to run on opengl instead or something.

Yeah, both c++ and python are of interest to me, and deploying to linux or win (I know you use mac and it is great that wxwidgets handles them all).

For Deploying to Linux and Windows, I use PyInstaller. Note: you may find another similar one with same name but, lowercase: pyinstaller. It is NOT the same as PyInstaller.

I made an App (in Formbuilder) to build the App. Still, need to use PyInstaller on the platform you’re designing for. You can PIP install it into those platforms.

Image of my App

Oh boy – those are new ones I have not looked at yet :slight_smile:

Avalonia looks very clean and modern and is mit. Not sure what the implications are for .net.

I can’t be the only one looking for a basic gui that can:

  • deploy to linux/win/mac
  • free with permissive license for binary release without source (no qt)
  • a clean look (unlike tkinter and such that look 1990s-vintage)
  • c/c++/python apis
  • a not-too-steep learning curve
  • responsive would be nice

I use vscode on both linux and win for cortex-m coding and love it, but could not get it running with wxwidgets – so I tried code:blocks/mingw64 (testing on win currently), which works but I miss the intellisense features (hover lookup…) and dark mode, but I can live with it.

Avalonia talks about visual-studio, which I presume is a paid offering – does it work with open-source vscode? Can it work with a regular g++/gcc compiler instead of .net (which I am guessing is also a paid tool)?

When I say plotting, what I am really needing is an efficient canvas line-segment draw. In my pysimplegui app I was able to receive four channels of 24b adc data (about 150kbaud average) over usb, plot time-domain to a canvas in realtime, and calculate/plot fft data to another canvas (just with 1-second updates). I was quite pleased to get enough number-crunching happening in parallel with the gui. I want to experiment with a similar application using a serial port stream and a new gui. I am just a hardware/embedded guy getting in over my head on desktop applications, but I do my best to hack my want through.

The mods will likely close this as off-topic, which is kinda a shame when some of these discussions go off in interesting directions, so thanks all for the pointers.

So does Pyinstaller generate a single binary executable? That would make python much more use to me.

I for one don’t think it’s OT.

Hello, not sure why are you doing graph in C++ (maybe you want to make a proprietary product ?), for real-time graph I recommend to use PyQtGraph lib. and you can package it with py2exe or similar tools to make a product.

For real-time graph, it is recommended to use event loop to handle data stream – it is too fast for event loop. Event loop is designed to handle UI relevant operations. Normally you should use a separate thread to handle data and update graph via some canvas context or OpenGL context regularly.

The big boy VS is free for open source and startup scale businesses.

Also gcc isn’t used for dotnet.

Avalonia has a VSCode extension for WYSWIG

Dotnet is a self compiling language maintained under the MIT License.

1 Like

I have not tried packaging with py2exe or Pyinstaller mentioned by @blackcoffee but it does sound useful to be able to create an executable from a python project.

In the pysimplegui project I did, I was using a daemon_thread to receive/save/process data from a usb-hid connection to my custom daq device. In the gui thread I was able to grab frames of data to update the display – the scope display was realtime while the fft was simply updated every second (on a 1-sec window). It was my first venture into desktop software and I learned a lot and was pretty happy with it (as hackey as it was).

Now I want to do something similar to learn a bit more c++ (but with a serial port stream this time instead of usb) and thought to try wxwidgets so it would work across linux/win/mac. I got a basic app running using wxformdesigner, code:blocks, and mingw64. However, as I dig in deeper to wxwidgets, I am concerned that I may not be able replicate the same sort of threading since wxwidgets seems to hide and take control of the event loop. I could be missing something, but I have not spent too much time on this yet.

Now, @marekr has got me looking into .net and c#, which I had thought were proprietary/paid but seem to now be open and cross-platform. So I am going to experiment a bit there next to see what I can figure out.

Hah, yes you got me off on a new tangent! From my little bit of research the last hour or so I have loaded dotnet6 on my linux box and am now going to put it on my win machine, then I will grab c# and see what I can learn. If all goes well I will dig into the avalonia lib. MIT or similar everywhere so what’s not to like? I wanted to get deeper into c++ (I have four decades of embedded C but not much c++) for oop but c# will also be good to learn.
thanks @marekr

…and just to point out that this is not totally off-topic, since the hardware I connect is all designed in kicad :slight_smile:

for GUI, it is almost recommended to do GUI related ops in the main thread. you can put command or events into a thread-safe queue, and your main thread (GUI) can handle them correctly.

1 Like

Ugh it’s as bad as Java. :scream:

Also despite Mono there are difficulties running on Linux.

Well, yeah, java can be verbose and bloated, but it does keep you from making silly mistakes. I wrote some for frc robotics a few years back. But I am now working through some c# tutorials, and will keep an open mind for the language. I do want to run on linux as well as win – what difficulties did you find on linux?

Take a look at “Rust”

There is opensource implementation of .Net runtime called mono

1 Like

Have a look at ths list of issues at GitHub - ThisIsNotRocketScience/GerberTools: Tools to load/edit/create/panelizer sets of gerber files

A post was split to a new topic: Learning to Develop in Kicad