From cce46332c4f40dadce43ba57a474734fcb1496de Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 13 Aug 2024 23:28:50 +0300 Subject: [PATCH] Make `display_label_popup` visible in UI Follows up on 34887aeef13390d1a2ae0835276e92c9d93548b6 (#271) --- labelme/app.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index 010f1c989..ad7c91a7f 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -129,7 +129,21 @@ 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." @@ -137,9 +151,19 @@ def __init__( ) 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")) @@ -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( @@ -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) @@ -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: