Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug editlabel window is marked while cursor on the below of screen #1462

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(
)

self.labelList = LabelListWidget()
self.pointList = LabelListWidget()
self.lastOpenDir = None

self.flag_dock = self.flag_widget = None
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion labelme/widgets/label_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down