Added combobox to the main view for displaying unique labels individually
This commit is contained in:
parent
bf8cc1d575
commit
e51bfce9a7
25
combobox.py
Normal file
25
combobox.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
|
||||||
|
class ComboBox(QWidget):
|
||||||
|
def __init__(self, parent=None, items=[]):
|
||||||
|
super(ComboBox, self).__init__(parent)
|
||||||
|
|
||||||
|
layout = QHBoxLayout()
|
||||||
|
self.cb = QComboBox()
|
||||||
|
self.items = items
|
||||||
|
self.cb.addItems(self.items)
|
||||||
|
|
||||||
|
self.cb.currentIndexChanged.connect(parent.comboSelectionChanged)
|
||||||
|
|
||||||
|
layout.addWidget(self.cb)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def update_items(self, items):
|
||||||
|
self.items = items
|
||||||
|
|
||||||
|
self.cb.clear()
|
||||||
|
self.cb.addItems(self.items)
|
||||||
34
labelImg.py
34
labelImg.py
@ -26,6 +26,7 @@ except ImportError:
|
|||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
|
||||||
|
from combobox import ComboBox
|
||||||
from libs.resources import *
|
from libs.resources import *
|
||||||
from libs.constants import *
|
from libs.constants import *
|
||||||
from libs.utils import *
|
from libs.utils import *
|
||||||
@ -136,6 +137,10 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
listLayout.addWidget(self.diffcButton)
|
listLayout.addWidget(self.diffcButton)
|
||||||
listLayout.addWidget(useDefaultLabelContainer)
|
listLayout.addWidget(useDefaultLabelContainer)
|
||||||
|
|
||||||
|
# Create and add combobox for showing unique labels in group
|
||||||
|
self.comboBox = ComboBox(self)
|
||||||
|
listLayout.addWidget(self.comboBox)
|
||||||
|
|
||||||
# Create and add a widget for showing current label items
|
# Create and add a widget for showing current label items
|
||||||
self.labelList = QListWidget()
|
self.labelList = QListWidget()
|
||||||
labelListContainer = QWidget()
|
labelListContainer = QWidget()
|
||||||
@ -147,6 +152,8 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.labelList.itemChanged.connect(self.labelItemChanged)
|
self.labelList.itemChanged.connect(self.labelItemChanged)
|
||||||
listLayout.addWidget(self.labelList)
|
listLayout.addWidget(self.labelList)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.dock = QDockWidget(getStr('boxLabelText'), self)
|
self.dock = QDockWidget(getStr('boxLabelText'), self)
|
||||||
self.dock.setObjectName(getStr('labels'))
|
self.dock.setObjectName(getStr('labels'))
|
||||||
self.dock.setWidget(labelListContainer)
|
self.dock.setWidget(labelListContainer)
|
||||||
@ -573,6 +580,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.labelFile = None
|
self.labelFile = None
|
||||||
self.canvas.resetState()
|
self.canvas.resetState()
|
||||||
self.labelCoordinates.clear()
|
self.labelCoordinates.clear()
|
||||||
|
self.comboBox.cb.clear()
|
||||||
|
|
||||||
def currentItem(self):
|
def currentItem(self):
|
||||||
items = self.labelList.selectedItems()
|
items = self.labelList.selectedItems()
|
||||||
@ -670,6 +678,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
item.setText(text)
|
item.setText(text)
|
||||||
item.setBackground(generateColorByText(text))
|
item.setBackground(generateColorByText(text))
|
||||||
self.setDirty()
|
self.setDirty()
|
||||||
|
self.updateComboBox()
|
||||||
|
|
||||||
# Tzutalin 20160906 : Add file list and dock to move faster
|
# Tzutalin 20160906 : Add file list and dock to move faster
|
||||||
def fileitemDoubleClicked(self, item=None):
|
def fileitemDoubleClicked(self, item=None):
|
||||||
@ -733,6 +742,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.labelList.addItem(item)
|
self.labelList.addItem(item)
|
||||||
for action in self.actions.onShapesPresent:
|
for action in self.actions.onShapesPresent:
|
||||||
action.setEnabled(True)
|
action.setEnabled(True)
|
||||||
|
self.updateComboBox()
|
||||||
|
|
||||||
def remLabel(self, shape):
|
def remLabel(self, shape):
|
||||||
if shape is None:
|
if shape is None:
|
||||||
@ -742,6 +752,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
self.labelList.takeItem(self.labelList.row(item))
|
self.labelList.takeItem(self.labelList.row(item))
|
||||||
del self.shapesToItems[shape]
|
del self.shapesToItems[shape]
|
||||||
del self.itemsToShapes[item]
|
del self.itemsToShapes[item]
|
||||||
|
self.updateComboBox()
|
||||||
|
|
||||||
def loadLabels(self, shapes):
|
def loadLabels(self, shapes):
|
||||||
s = []
|
s = []
|
||||||
@ -770,9 +781,20 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
shape.fill_color = generateColorByText(label)
|
shape.fill_color = generateColorByText(label)
|
||||||
|
|
||||||
self.addLabel(shape)
|
self.addLabel(shape)
|
||||||
|
self.updateComboBox()
|
||||||
self.canvas.loadShapes(s)
|
self.canvas.loadShapes(s)
|
||||||
|
|
||||||
|
def updateComboBox(self):
|
||||||
|
# Get the unique labels and add them to the Combobox.
|
||||||
|
itemsTextList = [str(self.labelList.item(i).text()) for i in range(self.labelList.count())]
|
||||||
|
|
||||||
|
uniqueTextList = list(set(itemsTextList))
|
||||||
|
# Add a null row for showing all the labels
|
||||||
|
uniqueTextList.append("")
|
||||||
|
uniqueTextList.sort()
|
||||||
|
|
||||||
|
self.comboBox.update_items(uniqueTextList)
|
||||||
|
|
||||||
def saveLabels(self, annotationFilePath):
|
def saveLabels(self, annotationFilePath):
|
||||||
annotationFilePath = ustr(annotationFilePath)
|
annotationFilePath = ustr(annotationFilePath)
|
||||||
if self.labelFile is None:
|
if self.labelFile is None:
|
||||||
@ -814,6 +836,16 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||||||
# fix copy and delete
|
# fix copy and delete
|
||||||
self.shapeSelectionChanged(True)
|
self.shapeSelectionChanged(True)
|
||||||
|
|
||||||
|
def comboSelectionChanged(self, index):
|
||||||
|
text = self.comboBox.cb.itemText(index)
|
||||||
|
for i in range(self.labelList.count()):
|
||||||
|
if text == "":
|
||||||
|
self.labelList.item(i).setCheckState(2)
|
||||||
|
elif text != self.labelList.item(i).text():
|
||||||
|
self.labelList.item(i).setCheckState(0)
|
||||||
|
else:
|
||||||
|
self.labelList.item(i).setCheckState(2)
|
||||||
|
|
||||||
def labelSelectionChanged(self):
|
def labelSelectionChanged(self):
|
||||||
item = self.currentItem()
|
item = self.currentItem()
|
||||||
if item and self.canvas.editing():
|
if item and self.canvas.editing():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user