Pan, Zoom, Refresh from python in pcbnew

So you’ve written a cool new layout modification utility in python. It sure would be nice to see the results on the screen. This is an issue I faced with my placement replicator script. It does what I want except that the user has to click the refresh button to see the results.

Now there’s a way to trigger zoom, pan, and refresh from python. As of this writing (March 20, 2017), you need to use one of the nightlies or build yourself.

To refresh the screen:


To pan and zoom, you need to supply x,y, width, height:

x = pcbnew.FromMM(10)
y = pcbnew.FromMM(10)
width  = pcbnew.FromMM(20)
height = pcbnew.FromMM(20)
pcbnew.WindowZoom(x, y, width, height)

Contributing to Kicad is painless

I initially searched and searched in pcbnew’s C code for python APIs like these. Eventually, I came to realize that they didn’t exist yet in pcbnew. So finally, I have my very first code contribution to an open source project.

I’ve been paid to write software for many years but it’s all been in-house stuff. My professional environment was pretty loosey-goosey, with very few formal constraints. 1 Over the years, I’ve read lots of stories about how open source projects can be a pain to deal with. Lots of coding standards, lots of requirements,… lots of hoops to jump through.2

This was not my experience with proposing these code changes to Kicad. I read the developer wiki, and attempted with follow the directions. I mailed the patch file to the developer email list, along with an introduction of who I am and what I’m trying to accomplish.

It was committed the same day.

Wayne, the kicad project lead, was very welcoming and encouraging. Although there were a couple things I missed, he went ahead and did the tweaks and pushed the change. Next time, I’ll know.

Most important to me, I’m excited to do more.



  1. This was mostly fine. On the one hand, a lot of bugs slipped through that shouldn’t have, but on the other, it meant that a lot of what we did was very much co-development/co-design with the users.

  2. sometimes protection of empires, but probably also a lot critical code. I’d hope that mysql, Apache, linux kernel, g++,… are strict. Hopefully, they’ve also found ways to be welcoming. I don’t know. I guess it’s often the negative news that we remember.

6 thoughts on “Pan, Zoom, Refresh from python in pcbnew”

    1. Hi,
      That sounds like a good idea. Is there a particular function you’re interested in? I could use it as a case study.
      I think that the hardest part of describing the process is finding the function to be added in the C code. I’m starting to make sense of it, but things are still tricky to find.

      1. I have no particular function in mind but it would be very interesting and helpful if you could describe how you implemented the refresh function in a step by step guide.

  1. Great blog! Lots of useful info.

    I tried the Refresh() and WindowZoom() functions as shown in this post. No effect, but no error message either in the PCBNEW Python shell. I’m using a nightly version from April 26, 2017 on a Windows 7 PC. Is there anything that’s changed since this post?

    1. My guess is that you’re in OpenGL or Cairo view mode. When I change out of legacy mode into either of these, zoom doesn’t work for me either.

      You’re the second question on this that I’ve gotten and now I finally tried it myself.

      Please try going to the view menu and switching to legacy mode and run it again. If it still doesn’t work, please let me know (since that means more is at play)

      I’ll look into fixing it for OpenGL and Cairo

      1. Doh! I thought about that after I posted. You’re absolutely correct: it works in Legacy mode, but not OpenGL.

Leave a Reply

Your email address will not be published. Required fields are marked *