Commit e7a7b64f authored by vdalv's avatar vdalv Committed by darrenl
Browse files

Add option to enable/disable label painting

parent 219e50db
......@@ -370,6 +370,12 @@ class MainWindow(QMainWindow, WindowMixin):
self.singleClassMode.setCheckable(True)
self.singleClassMode.setChecked(settings.get(SETTING_SINGLE_CLASS, False))
self.lastLabel = None
# Add option to enable/disable labels being painted at the top of bounding boxes
self.paintLabelsOption = QAction("Paint Labels", self)
self.paintLabelsOption.setShortcut("Ctrl+Shift+P")
self.paintLabelsOption.setCheckable(True)
self.paintLabelsOption.setChecked(False)
self.paintLabelsOption.triggered.connect(self.togglePaintLabelsOption)
addActions(self.menus.file,
(open, opendir, changeSavedir, openAnnotation, self.menus.recentFiles, save, save_format, saveAs, close, resetAll, quit))
......@@ -377,6 +383,7 @@ class MainWindow(QMainWindow, WindowMixin):
addActions(self.menus.view, (
self.autoSaving,
self.singleClassMode,
self.paintLabelsOption,
labels, advancedMode, None,
hideAll, showAll, None,
zoomIn, zoomOut, zoomOrg, None,
......@@ -709,6 +716,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.actions.shapeFillColor.setEnabled(selected)
def addLabel(self, shape):
shape.paintLabel = self.paintLabelsOption.isChecked()
item = HashableQListWidgetItem(shape.label)
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked)
......@@ -1399,7 +1407,10 @@ class MainWindow(QMainWindow, WindowMixin):
self.loadLabels(shapes)
self.canvas.verified = tYoloParseReader.verified
def togglePaintLabelsOption(self):
paintLabelsOptionChecked = self.paintLabelsOption.isChecked()
for shape in self.canvas.shapes:
shape.paintLabel = paintLabelsOptionChecked
def inverted(color):
return QColor(*[255 - v for v in color.getRgb()])
......
......@@ -37,12 +37,13 @@ class Shape(object):
point_size = 8
scale = 1.0
def __init__(self, label=None, line_color=None,difficult = False):
def __init__(self, label=None, line_color=None, difficult=False, paintLabel=False):
self.label = label
self.points = []
self.fill = False
self.selected = False
self.difficult = difficult
self.paintLabel = paintLabel
self._highlightIndex = None
self._highlightMode = self.NEAR_VERTEX
......@@ -110,19 +111,20 @@ class Shape(object):
painter.fillPath(vrtx_path, self.vertex_fill_color)
# Draw text at the top-left
min_x = sys.maxsize
min_y = sys.maxsize
for point in self.points:
min_x = min(min_x, point.x())
min_y = min(min_y, point.y())
if min_x != sys.maxsize and min_y != sys.maxsize:
font = QFont()
font.setPointSize(8)
font.setBold(True)
painter.setFont(font)
if(self.label == None):
self.label = ""
painter.drawText(min_x, min_y, self.label)
if self.paintLabel:
min_x = sys.maxsize
min_y = sys.maxsize
for point in self.points:
min_x = min(min_x, point.x())
min_y = min(min_y, point.y())
if min_x != sys.maxsize and min_y != sys.maxsize:
font = QFont()
font.setPointSize(8)
font.setBold(True)
painter.setFont(font)
if(self.label == None):
self.label = ""
painter.drawText(min_x, min_y, self.label)
if self.fill:
color = self.select_fill_color if self.selected else self.fill_color
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment