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): def __init__(self,aList):
self.last = aList # last item is the start of list 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 item = self.last
try: try:

View File

@ -220,28 +220,28 @@ if os.path.exists(libcef_so):
%{ %{
def OnPgmInit(self): def OnPgmInit(self):
print "hereA" print("hereA")
if not self.InitPgm(): if not self.InitPgm():
return False; return False;
print "hereB" print("hereB")
try: try:
# A KIWAY_PLAYER is a wx.Window # A KIWAY_PLAYER is a wx.Window
frame = Kiway.Player( FRAME_SCH, True ) frame = Kiway.Player( FRAME_SCH, True )
print "here0" print("here0")
except IOError as e: except IOError as e:
print 'Player()', e print('Player()', e)
return None return None
print "here1" print("here1")
Kiway.SetTop(frame) Kiway.SetTop(frame)
print "here2" print("here2")
return frame 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 * from pcbnew import *
size_0_6mm = wxSizeMM(0.6,0.6) size_0_6mm = wxSizeMM(0.6,0.6)
@ -38,11 +41,11 @@ pcb.Save("my2.kicad_pcb")
pcb = LoadBoard("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 m in pcb.GetModules():
for p in m.Pads(): for p in m.Pads():
print 'pad ', p.GetName(), p.GetPosition(), p.GetOffset() print('pad ', p.GetName(), p.GetPosition(), p.GetOffset())
# pcb.GetDesignSettings() # pcb.GetDesignSettings()

View File

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

View File

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

View File

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

View File

@ -1,8 +1,10 @@
from __future__ import print_function
import pcbnew import pcbnew
pcb = pcbnew.GetBoard() pcb = pcbnew.GetBoard()
for m in pcb.GetModules(): 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(): 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__': if __name__ == '__main__':
unittest.main() unittest.main()