conservative conversion of some python2-isms to py3-compatible code
This commit is contained in:
parent
9afb00d6ee
commit
67a8583e22
14
labelImg.py
14
labelImg.py
@ -48,7 +48,7 @@ class WindowMixin(object):
|
|||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow, WindowMixin):
|
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):
|
def __init__(self, filename=None):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
@ -472,7 +472,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.actions.editMode.setEnabled(not drawing)
|
self.actions.editMode.setEnabled(not drawing)
|
||||||
if not drawing and self.beginner():
|
if not drawing and self.beginner():
|
||||||
# Cancel creation.
|
# Cancel creation.
|
||||||
print 'Cancel creation.'
|
print('Cancel creation.')
|
||||||
self.canvas.setEditing(True)
|
self.canvas.setEditing(True)
|
||||||
self.canvas.restoreCursor()
|
self.canvas.restoreCursor()
|
||||||
self.actions.create.setEnabled(True)
|
self.actions.create.setEnabled(True)
|
||||||
@ -585,7 +585,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
# Can add differrent annotation formats here
|
# Can add differrent annotation formats here
|
||||||
try:
|
try:
|
||||||
if self.usingPascalVocFormat is True:
|
if self.usingPascalVocFormat is True:
|
||||||
print 'savePascalVocFormat save to:' + filename
|
print('savePascalVocFormat save to:' + filename)
|
||||||
lf.savePascalVocFormat(filename, shapes, unicode(self.filename), self.imageData,
|
lf.savePascalVocFormat(filename, shapes, unicode(self.filename), self.imageData,
|
||||||
self.lineColor.getRgb(), self.fillColor.getRgb())
|
self.lineColor.getRgb(), self.fillColor.getRgb())
|
||||||
else:
|
else:
|
||||||
@ -594,7 +594,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.labelFile = lf
|
self.labelFile = lf
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
return True
|
return True
|
||||||
except LabelFileError, e:
|
except LabelFileError as e:
|
||||||
self.errorMessage(u'Error saving label data',
|
self.errorMessage(u'Error saving label data',
|
||||||
u'<b>%s</b>' % e)
|
u'<b>%s</b>' % e)
|
||||||
return False
|
return False
|
||||||
@ -677,7 +677,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.adjustScale()
|
self.adjustScale()
|
||||||
|
|
||||||
def togglePolygons(self, value):
|
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)
|
item.setCheckState(Qt.Checked if value else Qt.Unchecked)
|
||||||
|
|
||||||
def loadFile(self, filename=None):
|
def loadFile(self, filename=None):
|
||||||
@ -699,7 +699,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
if LabelFile.isLabelFile(filename):
|
if LabelFile.isLabelFile(filename):
|
||||||
try:
|
try:
|
||||||
self.labelFile = LabelFile(filename)
|
self.labelFile = LabelFile(filename)
|
||||||
except LabelFileError, e:
|
except LabelFileError as e:
|
||||||
self.errorMessage(u'Error opening file',
|
self.errorMessage(u'Error opening file',
|
||||||
(u"<p><b>%s</b></p>"
|
(u"<p><b>%s</b></p>"
|
||||||
u"<p>Make sure <i>%s</i> is a valid label file.")\
|
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"
|
assert not self.image.isNull(), "cannot save empty image"
|
||||||
if self.hasLabels():
|
if self.hasLabels():
|
||||||
if self.defaultSaveDir is not None and len(str(self.defaultSaveDir)):
|
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)
|
imgFileName = os.path.basename(self.filename)
|
||||||
savedFileName = os.path.splitext(imgFileName)[0] + LabelFile.suffix
|
savedFileName = os.path.splitext(imgFileName)[0] + LabelFile.suffix
|
||||||
savedPath = os.path.join(str(self.defaultSaveDir), savedFileName)
|
savedPath = os.path.join(str(self.defaultSaveDir), savedFileName)
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class Canvas(QWidget):
|
|||||||
shapeMoved = pyqtSignal()
|
shapeMoved = pyqtSignal()
|
||||||
drawingPolygon = pyqtSignal(bool)
|
drawingPolygon = pyqtSignal(bool)
|
||||||
|
|
||||||
CREATE, EDIT = range(2)
|
CREATE, EDIT = list(range(2))
|
||||||
|
|
||||||
epsilon = 11.0
|
epsilon = 11.0
|
||||||
|
|
||||||
@ -456,12 +456,14 @@ class Canvas(QWidget):
|
|||||||
return QPointF(min(max(0, x2), max(x3, x4)), y3)
|
return QPointF(min(max(0, x2), max(x3, x4)), y3)
|
||||||
return QPointF(x, y)
|
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
|
"""For each edge formed by `points', yield the intersection
|
||||||
with the line segment `(x1,y1) - (x2,y2)`, if it exists.
|
with the line segment `(x1,y1) - (x2,y2)`, if it exists.
|
||||||
Also return the distance of `(x2,y2)' to the middle of the
|
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."""
|
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]
|
x3, y3 = points[i]
|
||||||
x4, y4 = points[(i+1) % 4]
|
x4, y4 = points[(i+1) % 4]
|
||||||
denom = (y4-y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)
|
denom = (y4-y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)
|
||||||
@ -506,7 +508,7 @@ class Canvas(QWidget):
|
|||||||
def keyPressEvent(self, ev):
|
def keyPressEvent(self, ev):
|
||||||
key = ev.key()
|
key = ev.key()
|
||||||
if key == Qt.Key_Escape and self.current:
|
if key == Qt.Key_Escape and self.current:
|
||||||
print 'ESC press'
|
print('ESC press')
|
||||||
self.current = None
|
self.current = None
|
||||||
self.drawingPolygon.emit(False)
|
self.drawingPolygon.emit(False)
|
||||||
self.update()
|
self.update()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user