diff --git a/labelme/app.py b/labelme/app.py index 9a83a3711..5939bda5c 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -107,6 +107,7 @@ def __init__( ) self.labelList = LabelListWidget() + self.pointList = LabelListWidget() self.lastOpenDir = None self.flag_dock = self.flag_widget = None @@ -126,6 +127,15 @@ def __init__( self.shape_dock.setObjectName("Labels") self.shape_dock.setWidget(self.labelList) + # pointList + # self.pointList.itemSelectionChanged.connect(self.labelSelectionChanged) + # self.pointList.itemDoubleClicked.connect(self.editLabel) + # self.pointList.itemChanged.connect(self.labelItemChanged) + # self.pointList.itemDropped.connect(self.labelOrderChanged) + self.shape_dock = QtWidgets.QDockWidget('坐标列表', self) + self.shape_dock.setObjectName("Labels") + self.shape_dock.setWidget(self.pointList) + self.uniqLabelList = UniqueLabelQListWidget() self.uniqLabelList.setToolTip( self.tr( @@ -987,6 +997,7 @@ def status(self, message, delay=5000): def resetState(self): self.labelList.clear() + self.pointList.clear() self.filename = None self.imagePath = None self.imageData = None @@ -1104,6 +1115,7 @@ def editLabel(self, item=None): flags=shape.flags, group_id=shape.group_id, description=shape.description, + centralWidget=self.centralWidget() ) if text is None: return @@ -1170,6 +1182,14 @@ def shapeSelectionChanged(self, selected_shapes): item = self.labelList.findItemByShape(shape) self.labelList.selectItem(item) self.labelList.scrollToItem(item) + + # pointList + self.pointList.clear() + for point_item in shape.points: + point_text = f'{point_item.x()},{point_item.y()}' + point_list_item = LabelListWidgetItem(point_text, shape) + point_list_item.setText('{}'.format(html.escape(point_text))) + self.pointList.addItem(point_list_item) self._noSelectionSlot = False n_selected = len(selected_shapes) self.actions.delete.setEnabled(n_selected) @@ -1183,6 +1203,7 @@ def addLabel(self, shape): else: text = "{} ({})".format(shape.label, shape.group_id) label_list_item = LabelListWidgetItem(text, shape) + self.labelList.addItem(label_list_item) if self.uniqLabelList.findItemByLabel(shape.label) is None: item = self.uniqLabelList.createItemFromLabel(shape.label) @@ -1200,6 +1221,7 @@ def addLabel(self, shape): ) ) + def _update_shape_color(self, shape): r, g, b = self._get_rgb_by_label(shape.label) shape.line_color = QtGui.QColor(r, g, b) diff --git a/labelme/widgets/label_dialog.py b/labelme/widgets/label_dialog.py index 1047a5e38..beabce3ab 100644 --- a/labelme/widgets/label_dialog.py +++ b/labelme/widgets/label_dialog.py @@ -199,7 +199,7 @@ def getGroupId(self): return int(group_id) return None - def popUp(self, text=None, move=True, flags=None, group_id=None, description=None): + def popUp(self, text=None, move=True, flags=None, group_id=None, description=None,centralWidget=None): if self._fit_to_content["row"]: self.labelList.setMinimumHeight( self.labelList.sizeHintForRow(0) * self.labelList.count() + 2 @@ -232,6 +232,13 @@ def popUp(self, text=None, move=True, flags=None, group_id=None, description=Non self.edit.completer().setCurrentRow(row) self.edit.setFocus(QtCore.Qt.PopupFocusReason) if move: + if centralWidget: + h = centralWidget.height() + + x = QtGui.QCursor.pos().x() + dialog_height = self.sizeHint().height() + y = QtGui.QCursor.pos().y() if QtGui.QCursor.pos().y() < h else h - int(dialog_height / 2) + QtGui.QCursor.setPos(x, y) self.move(QtGui.QCursor.pos()) if self.exec_(): return (