Fix incompatibilites between Python 2 and Python 3

This commit is contained in:
Thomas Pointhuber 2018-08-04 17:11:45 +02:00 committed by Maciej Suminski
parent 7548a3b1bf
commit 8805706ccb
8 changed files with 72 additions and 63 deletions

View File

@ -39,7 +39,10 @@
def __init__(self,aList):
self.last = aList # last item is the start of list
def next(self): # get the next item
def next(self): # get the next item, Python 2 way to implement an iterator
return self.__next__()
def __next__(self): # get the next item
item = self.last
try:

View File

@ -220,28 +220,28 @@ if os.path.exists(libcef_so):
%{
def OnPgmInit(self):
print "hereA"
print("hereA")
if not self.InitPgm():
return False;
print "hereB"
print("hereB")
try:
# A KIWAY_PLAYER is a wx.Window
frame = Kiway.Player( FRAME_SCH, True )
print "here0"
print("here0")
except IOError as e:
print 'Player()', e
print('Player()', e)
return None
print "here1"
print("here1")
Kiway.SetTop(frame)
print "here2"
print("here2")
return frame
%}

View File

@ -1,4 +1,7 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python
from __future__ import print_function
from pcbnew import *
size_0_6mm = wxSizeMM(0.6,0.6)
@ -38,11 +41,11 @@ pcb.Save("my2.kicad_pcb")
pcb = LoadBoard("my2.kicad_pcb")
print map( lambda x: x.GetReference() , list(pcb.GetModules()))
print(map( lambda x: x.GetReference() , list(pcb.GetModules())))
for m in pcb.GetModules():
for p in m.Pads():
print 'pad ', p.GetName(), p.GetPosition(), p.GetOffset()
print('pad ', p.GetName(), p.GetPosition(), p.GetOffset())
# pcb.GetDesignSettings()

View File

@ -7,7 +7,7 @@ filename=sys.argv[1]
pcb = LoadBoard(filename)
for module in pcb.GetModules():
print "* Module: %s"%module.GetReference()
print("* Module: %s" % module.GetReference())
module.Value().SetVisible(False) # set Value as Hidden
module.Reference().SetVisible(True) # set Reference as Visible

View File

@ -1,4 +1,7 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
from pcbnew import *
@ -11,7 +14,7 @@ FromUnits = FromMM
#ToUnits=ToMils
#FromUnits=FromMils
print "LISTING VIAS:"
print("LISTING VIAS:")
for item in pcb.GetTracks():
if type(item) is VIA:
@ -19,7 +22,7 @@ for item in pcb.GetTracks():
pos = item.GetPosition()
drill = item.GetDrillValue()
width = item.GetWidth()
print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width))
print(" * Via: %s - %f/%f " % (ToUnits(pos), ToUnits(drill), ToUnits(width)))
elif type(item) is TRACK:
@ -27,40 +30,39 @@ for item in pcb.GetTracks():
end = item.GetEnd()
width = item.GetWidth()
print " * Track: %s to %s, width %f" % (ToUnits(start),ToUnits(end),ToUnits(width))
print(" * Track: %s to %s, width %f" % (ToUnits(start), ToUnits(end), ToUnits(width)))
else:
print "Unknown type %s" % type(item)
print("Unknown type %s" % type(item))
print ""
print "LIST DRAWINGS:"
print("")
print("LIST DRAWINGS:")
for item in pcb.GetDrawings():
if type(item) is TEXTE_PCB:
print "* Text: '%s' at %s"%(item.GetText(), item.GetPosition())
print("* Text: '%s' at %s" % (item.GetText(), item.GetPosition()))
elif type(item) is DRAWSEGMENT:
print "* Drawing: %s"%item.GetShapeStr() # dir(item)
print("* Drawing: %s" % item.GetShapeStr()) # dir(item)
else:
print type(item)
print(type(item))
print ""
print "LIST MODULES:"
print("")
print("LIST MODULES:")
for module in pcb.GetModules():
print "* Module: %s at %s"%(module.GetReference(), ToUnits(module.GetPosition()))
print("* Module: %s at %s" % (module.GetReference(), ToUnits(module.GetPosition())))
print ""
print "Nets cnt: ", pcb.GetNetCount()
print "track w cnt:",len(pcb.GetTrackWidthList())
print "via s cnt:",len(pcb.GetViasDimensionsList())
print("")
print("Nets cnt: ", pcb.GetNetCount())
print("track w cnt:", len(pcb.GetTrackWidthList()))
print("via s cnt:", len(pcb.GetViasDimensionsList()))
print ""
print "LIST ZONES:", pcb.GetAreaCount()
print("")
print("LIST ZONES:", pcb.GetAreaCount())
for idx in range(0, pcb.GetAreaCount()):
zone=pcb.GetArea(idx)
print "zone:", idx, "priority:", zone.GetPriority(), "netname", zone.GetNetname()
print ""
print "NetClasses:", pcb.GetNetClasses().GetCount(),
print("zone:", idx, "priority:", zone.GetPriority(), "netname", zone.GetNetname())
print("")
print("NetClasses:", pcb.GetNetClasses().GetCount())

View File

@ -1,11 +1,11 @@
from __future__ import print_function
import pcbnew
pcb = pcbnew.GetBoard()
for m in pcb.GetModules():
print m.GetPosition()
print(m.GetPosition())
for p in m.Pads():
print "p=>",p.GetPosition(),p.GetName()
print p.GetPosition()
print("p=>", p.GetPosition(), p.GetName())
print(p.GetPosition())

View File

@ -1,8 +1,10 @@
from __future__ import print_function
import pcbnew
pcb = pcbnew.GetBoard()
for m in pcb.GetModules():
print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition()
print(m.GetReference(), "(", m.GetValue(), ") at ", m.GetPosition())
for p in m.Pads():
print " pad",p.GetName(), "at",p.GetPosition()
print(" pad", p.GetName(), "at", p.GetPosition())

View File

@ -45,4 +45,3 @@ class TestPCBLoad(unittest.TestCase):
if __name__ == '__main__':
unittest.main()