How to call a function every time I run pcbnew.Refresh() in plugins

I was trying to add shortcut to scripts. Shortcut works once I refresh the plugins.
But when I use some other plugin which uses pcbnew.Refresh() or I do pcbnew.Refresh(), it won’t work as pcbnew by default doesn’t have the plugins in GUI.
Any workaround to run the functions every time pcbnew.Refresh() is invoked??

Code which I have tried: https://github.com/Quantum-AI-shadow/kicad/blob/main/plugins/align_short.py

No, there are no hooks like that.

But you may have more luck if you add your item to one of the sidebars instead of top toolbar or menubar because those are rebuilt often on various triggers. I don’t think sidebars are rebuilt so your custom item should persist.

Proper fix for this would need actual shortcut support for plugins on kicad side.

1 Like

Thanks for the reply… I will try that
Is there any template or any repo to add it to side bar?

Not that I know of. But it’s similar to what you do, you just have to find the right wxAuiToolbar of the window instead of getting it’s menubar.

1 Like

Thanks!
I will check for sure