From 7be0a01af8c4653df9aaeec9c8a1147c27e206b3 Mon Sep 17 00:00:00 2001 From: zhangjie Date: Wed, 29 Nov 2017 21:20:14 +0800 Subject: [PATCH] change color when label has changed --- labelImg.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/labelImg.py b/labelImg.py index e76b6602..2d0f67b9 100755 --- a/labelImg.py +++ b/labelImg.py @@ -235,7 +235,7 @@ class MainWindow(QMainWindow, WindowMixin): 'Ctrl+Shift+S', 'save-as', u'Save labels to a different file', enabled=False) close = action('&Close', self.closeFile, 'Ctrl+W', 'close', u'Close current file') - + resetAll = action('&ResetAll', self.resetAll, None, 'resetall', u'Reset all') color1 = action('Box Line Color', self.chooseColor1, @@ -607,6 +607,7 @@ class MainWindow(QMainWindow, WindowMixin): text = self.labelDialog.popUp(item.text()) if text is not None: item.setText(text) + item.setBackground(generateColorByText(text)) self.setDirty() # Tzutalin 20160906 : Add file list and dock to move faster @@ -699,7 +700,7 @@ class MainWindow(QMainWindow, WindowMixin): shape.fill_color = QColor(*fill_color) else: shape.fill_color = generateColorByText(label) - + self.addLabel(shape) self.canvas.loadShapes(s) @@ -752,6 +753,7 @@ class MainWindow(QMainWindow, WindowMixin): label = item.text() if label != shape.label: shape.label = item.text() + shape.line_color = generateColorByText(shape.label) self.setDirty() else: # User probably changed item visibility self.canvas.setShapeVisible(shape, item.checkState() == Qt.Checked) @@ -912,7 +914,7 @@ class MainWindow(QMainWindow, WindowMixin): # read data first and store for saving into label file. self.imageData = read(unicodeFilePath, None) self.labelFile = None - + image = QImage.fromData(self.imageData) if image.isNull(): self.errorMessage(u'Error opening file', @@ -1081,10 +1083,10 @@ class MainWindow(QMainWindow, WindowMixin): defaultOpenDirPath = os.path.dirname(self.filePath) if self.filePath else '.' dirpath = ustr(QFileDialog.getExistingDirectory(self, - '%s - Open Directory' % __appname__, defaultOpenDirPath, + '%s - Open Directory' % __appname__, defaultOpenDirPath, QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)) self.importDirImages(dirpath) - + def importDirImages(self, dirpath): if not self.mayContinue() or not dirpath: return