diff --git a/labelImg.py b/labelImg.py index ab74772c..be1fa65c 100755 --- a/labelImg.py +++ b/labelImg.py @@ -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'%s' % 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"
%s
" u"Make sure %s 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) diff --git a/libs/canvas.py b/libs/canvas.py index be211e23..1e76331c 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -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()