conservative conversion of some python2-isms to py3-compatible code

This commit is contained in:
Ryan Flynn 2016-12-31 14:18:59 -05:00
parent 9afb00d6ee
commit 67a8583e22
2 changed files with 13 additions and 11 deletions

View File

@ -48,7 +48,7 @@ class WindowMixin(object):
class MainWindow(QMainWindow, WindowMixin):
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = range(3)
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = list(range(3))
def __init__(self, filename=None):
super(MainWindow, self).__init__()
@ -472,7 +472,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.actions.editMode.setEnabled(not drawing)
if not drawing and self.beginner():
# Cancel creation.
print 'Cancel creation.'
print('Cancel creation.')
self.canvas.setEditing(True)
self.canvas.restoreCursor()
self.actions.create.setEnabled(True)
@ -585,7 +585,7 @@ class MainWindow(QMainWindow, WindowMixin):
# Can add differrent annotation formats here
try:
if self.usingPascalVocFormat is True:
print 'savePascalVocFormat save to:' + filename
print('savePascalVocFormat save to:' + filename)
lf.savePascalVocFormat(filename, shapes, unicode(self.filename), self.imageData,
self.lineColor.getRgb(), self.fillColor.getRgb())
else:
@ -594,7 +594,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.labelFile = lf
self.filename = filename
return True
except LabelFileError, e:
except LabelFileError as e:
self.errorMessage(u'Error saving label data',
u'<b>%s</b>' % e)
return False
@ -677,7 +677,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.adjustScale()
def togglePolygons(self, value):
for item, shape in self.itemsToShapes.iteritems():
for item, shape in self.itemsToShapes.items():
item.setCheckState(Qt.Checked if value else Qt.Unchecked)
def loadFile(self, filename=None):
@ -699,7 +699,7 @@ class MainWindow(QMainWindow, WindowMixin):
if LabelFile.isLabelFile(filename):
try:
self.labelFile = LabelFile(filename)
except LabelFileError, e:
except LabelFileError as e:
self.errorMessage(u'Error opening file',
(u"<p><b>%s</b></p>"
u"<p>Make sure <i>%s</i> is a valid label file.")\
@ -936,7 +936,7 @@ class MainWindow(QMainWindow, WindowMixin):
assert not self.image.isNull(), "cannot save empty image"
if self.hasLabels():
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
print 'handle the image:' + self.filename
print('handle the image:' + self.filename)
imgFileName = os.path.basename(self.filename)
savedFileName = os.path.splitext(imgFileName)[0] + LabelFile.suffix
savedPath = os.path.join(str(self.defaultSaveDir), savedFileName)

View File

@ -20,7 +20,7 @@ class Canvas(QWidget):
shapeMoved = pyqtSignal()
drawingPolygon = pyqtSignal(bool)
CREATE, EDIT = range(2)
CREATE, EDIT = list(range(2))
epsilon = 11.0
@ -456,12 +456,14 @@ class Canvas(QWidget):
return QPointF(min(max(0, x2), max(x3, x4)), y3)
return QPointF(x, y)
def intersectingEdges(self, (x1, y1), (x2, y2), points):
def intersectingEdges(self, x1y1, x2y2, points):
"""For each edge formed by `points', yield the intersection
with the line segment `(x1,y1) - (x2,y2)`, if it exists.
Also return the distance of `(x2,y2)' to the middle of the
edge along with its index, so that the one closest can be chosen."""
for i in xrange(4):
x1, y1 = x1y1
x2, y2 = x2y2
for i in range(4):
x3, y3 = points[i]
x4, y4 = points[(i+1) % 4]
denom = (y4-y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)
@ -506,7 +508,7 @@ class Canvas(QWidget):
def keyPressEvent(self, ev):
key = ev.key()
if key == Qt.Key_Escape and self.current:
print 'ESC press'
print('ESC press')
self.current = None
self.drawingPolygon.emit(False)
self.update()