Skip to content

Commit

Permalink
Make display_label_popup visible in UI
Browse files Browse the repository at this point in the history
Follows up on 34887ae (#271)
  • Loading branch information
akx committed Aug 13, 2024
1 parent 80bd66e commit cce4633
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,41 @@ def __init__(
self.shape_dock.setObjectName("Labels")
self.shape_dock.setWidget(self.labelList)

self.display_label_popup_checkbox = QtWidgets.QCheckBox(
self.tr("Display Label Popup"),
)
self.display_label_popup_checkbox.setChecked(
self._config["display_label_popup"],
)
self.display_label_popup_checkbox.setToolTip(
self.tr(
"Display label popup when creating an object (otherwise, use label selected above)"
)
)

self.uniqLabelList = UniqueLabelQListWidget()
self.uniqLabelList.itemSelectionChanged.connect(self.uniqLabelSelectionChanged)

self.uniqLabelList.setToolTip(
self.tr(
"Select label to start annotating for it. " "Press 'Esc' to deselect."
)
)
for label in self._config["labels"] or ():
self._ensure_label_in_list(label)

label_list_layout = QtWidgets.QVBoxLayout()
label_list_layout.setContentsMargins(0, 0, 0, 0)
label_list_layout.setSpacing(0)
label_list_layout.addWidget(self.uniqLabelList)
label_list_layout.addWidget(self.display_label_popup_checkbox)

self.label_dock = QtWidgets.QDockWidget(self.tr("Label List"), self)
self.label_dock.setObjectName("Label List")
self.label_dock.setWidget(self.uniqLabelList)
label_list_widget = QtWidgets.QWidget()
label_list_widget.setLayout(label_list_layout)
self.label_dock.setWidget(label_list_widget)
self.update_display_label_popup_checkbox()

self.fileSearch = QtWidgets.QLineEdit()
self.fileSearch.setPlaceholderText(self.tr("Search Filename"))
Expand Down Expand Up @@ -1259,6 +1283,18 @@ def _update_item(self, item, text, flags, group_id, description):
item.setText("{} ({})".format(shape.label, shape.group_id))
self.setDirty()
self._ensure_label_in_list(shape.label)
self.update_display_label_popup_checkbox()

def uniqLabelSelectionChanged(self):
self.update_display_label_popup_checkbox()

def update_display_label_popup_checkbox(self):
has_selected_item = bool(self.uniqLabelList.selectedItems())
# `display_label_popup` couldn't have an effect if no item is selected,
# so disable and uncheck it as necessary.
self.display_label_popup_checkbox.setEnabled(has_selected_item)
if not has_selected_item:
self.display_label_popup_checkbox.setChecked(True)

def fileSearchChanged(self):
self.importDirImages(
Expand Down Expand Up @@ -1309,6 +1345,7 @@ def addLabel(self, shape):
label_list_item = LabelListWidgetItem(text, shape)
self.labelList.addItem(label_list_item)
self._ensure_label_in_list(shape.label)
self.update_display_label_popup_checkbox()
self.labelDialog.addLabelHistory(shape.label)
for action in self.actions.onShapesPresent:
action.setEnabled(True)
Expand Down Expand Up @@ -1521,7 +1558,8 @@ def newShape(self):
flags = {}
group_id = None
description = ""
if self._config["display_label_popup"] or not text:
display_label_popup = self.display_label_popup_checkbox.isChecked()
if display_label_popup or not text:
previous_text = self.labelDialog.edit.text()
text, flags, group_id, description = self.labelDialog.popUp(text)
if not text:
Expand Down

0 comments on commit cce4633

Please sign in to comment.