← Back to team overview

kicad-developers team mailing list archive

Re: more pythonic scripting API for pcbnew

 

Hi Brian,

 I see your point, but the problem with that is interoperability, for example
if we mix up modules which work with pcbnew, they could change units,
and mix them all up.

   I have proposed on the ether pad to do something like:

   Point.mm(10, 10), which would, under the hood do:

class Point:
    def __init__(x, y, unit):
       …

    @staticmethod
     def mm(x,y):
          return Point(x, y, unit=MM)


how does it sound?


I’m also trying to think if there is any way to handle it within a context,

    with Units(MM):  
        point = Point(10,10)

But I haven’t found how to push the context and make it available to Point..  

Miguel Ángel Ajo


On Friday, 16 de January de 2015 at 11:03, Brian Sidebotham wrote:

> On 15 January 2015 at 10:20, Miguel Ángel Ajo <majopela@xxxxxxxxxx (mailto:majopela@xxxxxxxxxx)> wrote:
> > Yesterday I wrote a proposal for discussion here:
> >  
> > http://pads.kicad-pcb.org/p/kicad-scripting-layer (please write your name
> > for your color
> > using the top right icon, so what you write can be identified to you).
> >  
> > I tried not to look too much into the original Piers proposal,
> > to do a true top-down design (“how do I like to interact with kicad
> > objects?”)
> >  
> > In the end, it looks quite much like Piers proposal, just with the
> > difference
> > of Point/Size objects receiving the unit.
> >  
> > I was trying to be as pythonic as possible avoiding set_/get_ methods,
> > and instead rely on attributes and implicit setters/getters.
> >  
> > The listed options are not exclusive, just different ways of doing the same.
> >  
> > Please feel free to write about other use cases, or copy, paste, then modify
> > my blocks
> > to provide different possible interactions.
> >  
> > Best,
> > Miguel Ángel.
> >  
> > Miguel Ángel Ajo
>  
> Hi Miguel,
>  
> I thought I'd add my thoughts here instead of changing what others have done.
>  
> I see that someone doesn't like the Point( 10, 10, unit=MM ) paradime
> for creating a 2D vector.
>  
> Personally, I prefer that construct compared to the proposed point_mm(
> 10, 10 ) by quite a long way.
>  
> But, it's of course a pain to always use unit=MM. Generally we know
> the units we're going to work with when we start with pcbnew scripting
> so it would be good to be able to do something like
> pcbnew.default_units = MM somewhere near the start of the script and
> then all 2D vectors can be created without the unit=MM additional
> argument, such as: Point( 10, 10 ) instead.
>  
> That would make a nicer interface in my opinion. I only had a chance
> to have a quick look at it. Thanks for getting something together for
> people to look at.
>  
> Best Regards,
>  
> Brian.
>  
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx (mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx)
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>  
>  



Follow ups

References