提交 1c9488f2 编写于 作者: K Kentaro Wada

Annotate label from list

上级 c9e06c6f
......@@ -90,7 +90,8 @@ class WindowMixin(object):
class MainWindow(QMainWindow, WindowMixin):
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = 0, 1, 2
def __init__(self, filename=None, output=None, store_data=True):
def __init__(self, filename=None, output=None, store_data=True,
labels=None):
super(MainWindow, self).__init__()
self.setWindowTitle(__appname__)
......@@ -103,7 +104,7 @@ class MainWindow(QMainWindow, WindowMixin):
self.screencast = "screencast.ogv"
# Main widgets and related state.
self.labelDialog = LabelDialog(parent=self)
self.labelDialog = LabelDialog(parent=self, labels=labels)
self.labelList = QListWidget()
self.itemsToShapes = []
......@@ -610,6 +611,7 @@ class MainWindow(QMainWindow, WindowMixin):
text = self.labelDialog.popUp()
if text is not None:
self.addLabel(self.canvas.setLastLabel(text))
self.labelDialog.addLabelHistory(text)
if self.beginner(): # Switch to edit mode.
self.canvas.setEditing(True)
self.actions.create.setEnabled(True)
......@@ -962,12 +964,16 @@ def main():
parser.add_argument('--output', '-O', '-o', help='output label name')
parser.add_argument('--nodata', dest='store_data', action='store_false',
help='Stop storing image data to JSON file.')
parser.add_argument('--labels', help='Camma separated list of labels')
args = parser.parse_args()
if args.labels is not None:
args.labels = args.labels.split(',')
app = QApplication(sys.argv)
app.setApplicationName(__appname__)
app.setWindowIcon(newIcon("app"))
win = MainWindow(args.filename, args.output, args.store_data)
win = MainWindow(args.filename, args.output, args.store_data, args.labels)
win.show()
win.raise_()
sys.exit(app.exec_())
......@@ -36,7 +36,7 @@ BB = QDialogButtonBox
class LabelDialog(QDialog):
def __init__(self, text="Enter object label", parent=None):
def __init__(self, text="Enter object label", parent=None, labels=None):
super(LabelDialog, self).__init__(parent)
self.edit = QLineEdit()
self.edit.setPlaceholderText(text)
......@@ -44,14 +44,30 @@ class LabelDialog(QDialog):
self.edit.editingFinished.connect(self.postProcess)
layout = QVBoxLayout()
layout.addWidget(self.edit)
# buttons
self.buttonBox = bb = BB(BB.Ok | BB.Cancel, Qt.Horizontal, self)
bb.button(BB.Ok).setIcon(newIcon('done'))
bb.button(BB.Cancel).setIcon(newIcon('undo'))
bb.accepted.connect(self.validate)
bb.rejected.connect(self.reject)
layout.addWidget(bb)
# label_list
self.labelList = QListWidget()
if labels:
self.labelList.addItems(labels)
self.labelList.currentItemChanged.connect(self.labelSelected)
layout.addWidget(self.labelList)
self.setLayout(layout)
def addLabelHistory(self, label):
if self.labelList.findItems(label, Qt.MatchExactly):
return
self.labelList.addItem(label)
self.labelList.sortItems()
def labelSelected(self, item):
self.edit.setText(item.text())
def validate(self):
if PYQT5:
if self.edit.text().strip():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册