From ddb9708ce9b25c81f56cc15f84f798578d3f66fd Mon Sep 17 00:00:00 2001 From: Alias_z Date: Mon, 17 Jul 2023 09:55:15 +0200 Subject: [PATCH 1/3] support group view --- ui/label_dock.py | 13 ++++++++++++- ui/label_dock.ui | 17 +++++++++++++++++ widgets/labels_dock_widget.py | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ui/label_dock.py b/ui/label_dock.py index bf08096..54bd230 100644 --- a/ui/label_dock.py +++ b/ui/label_dock.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file '/home/super/PycharmProjects/ISAT_with_segment_anything/ui/label_dock.ui' +# Form implementation generated from reading ui file 'label_dock.ui' # # Created by: PyQt5 UI code generator 5.15.7 # @@ -27,6 +27,15 @@ class Ui_Form(object): self.checkBox_visible = QtWidgets.QCheckBox(self.widget) self.checkBox_visible.setObjectName("checkBox_visible") self.horizontalLayout.addWidget(self.checkBox_visible) + self.comboBox_group_select = QtWidgets.QComboBox(self.widget) + self.comboBox_group_select.setObjectName("comboBox_group_select") + self.horizontalLayout.addWidget(self.comboBox_group_select) + self.button_prev_group = QtWidgets.QPushButton(self.widget) + self.button_prev_group.setObjectName("button_prev_group") + self.horizontalLayout.addWidget(self.button_prev_group) + self.button_next_group = QtWidgets.QPushButton(self.widget) + self.button_next_group.setObjectName("button_next_group") + self.horizontalLayout.addWidget(self.button_next_group) self.verticalLayout.addWidget(self.widget) self.listWidget = QtWidgets.QListWidget(Form) self.listWidget.setObjectName("listWidget") @@ -39,3 +48,5 @@ class Ui_Form(object): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.checkBox_visible.setText(_translate("Form", "Visible")) + self.button_prev_group.setText(_translate("Form", "Previous")) + self.button_next_group.setText(_translate("Form", "Next")) diff --git a/ui/label_dock.ui b/ui/label_dock.ui index 140b909..119d32d 100644 --- a/ui/label_dock.ui +++ b/ui/label_dock.ui @@ -42,6 +42,23 @@ + + + + + + + Previous + + + + + + + Next + + + diff --git a/widgets/labels_dock_widget.py b/widgets/labels_dock_widget.py index 8166b31..2393a00 100644 --- a/widgets/labels_dock_widget.py +++ b/widgets/labels_dock_widget.py @@ -16,6 +16,11 @@ class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): self.listWidget.itemSelectionChanged.connect(self.set_polygon_selected) self.checkBox_visible.stateChanged.connect(self.set_all_polygon_visible) + # addded group view + self.comboBox_group_select.currentIndexChanged.connect(self.set_group_polygon_visible) + self.button_next_group.clicked.connect(self.go_to_next_group) + self.button_prev_group.clicked.connect(self.go_to_prev_group) + self.listWidget.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu) self.listWidget.customContextMenuRequested.connect( self.right_button_menu) @@ -75,6 +80,11 @@ class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): if self.mainwindow.load_finished: self.mainwindow.set_saved_state(False) + unique_groups = {polygon.group for polygon in self.mainwindow.polygons} + self.comboBox_group_select.clear() + self.comboBox_group_select.addItem('All') # add an option to view all groups + self.comboBox_group_select.addItems(sorted(unique_groups)) + def set_selected(self, polygon): item = self.polygon_item_dict[polygon] if polygon.isSelected(): @@ -114,3 +124,29 @@ class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): check_box = widget.findChild(QtWidgets.QCheckBox, 'check_box') check_box.setChecked(visible) self.checkBox_visible.setChecked(visible) + + def set_group_polygon_visible(self): + selected_group = self.comboBox_group_select.currentText() + + for polygon, item in self.polygon_item_dict.items(): + widget = self.listWidget.itemWidget(item) + check_box = widget.findChild(QtWidgets.QCheckBox, 'check_box') + + if selected_group == 'All' or polygon.group == selected_group: + check_box.setChecked(True) + else: + check_box.setChecked(False) + + def go_to_next_group(self): + current_index = self.comboBox_group_select.currentIndex() + max_index = self.comboBox_group_select.count() - 1 + if current_index < max_index: + self.comboBox_group_select.setCurrentIndex(current_index + 1) + self.set_group_polygon_visible() + + def go_to_prev_group(self): + current_index = self.comboBox_group_select.currentIndex() + if current_index > 0: + self.comboBox_group_select.setCurrentIndex(current_index - 1) + self.set_group_polygon_visible() + From 30351d5b6d6560cee044fbc5a8971373e0893e82 Mon Sep 17 00:00:00 2001 From: Alias_z Date: Mon, 17 Jul 2023 10:55:45 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=AF=E6=8C=81group=20view=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- widgets/labels_dock_widget.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/widgets/labels_dock_widget.py b/widgets/labels_dock_widget.py index 2393a00..f66d196 100644 --- a/widgets/labels_dock_widget.py +++ b/widgets/labels_dock_widget.py @@ -137,16 +137,34 @@ class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): else: check_box.setChecked(False) + def zoom_to_group(self): + selected_group = self.comboBox_group_select.currentText() + polygons_in_group = [polygon for polygon, item in self.polygon_item_dict.items() + if polygon.group == selected_group] + if not polygons_in_group: + return + min_x = min(min(vertex.x() for vertex in polygon.vertexs) for polygon in polygons_in_group) + min_y = min(min(vertex.y() for vertex in polygon.vertexs) for polygon in polygons_in_group) + max_x = max(max(vertex.x() for vertex in polygon.vertexs) for polygon in polygons_in_group) + max_y = max(max(vertex.y() for vertex in polygon.vertexs) for polygon in polygons_in_group) + margin = 20 + bounding_rect = QtCore.QRectF(min_x - margin, min_y - margin, max_x - min_x + 2*margin, max_y - min_y + 2*margin) + self.mainwindow.view.fitInView(bounding_rect, QtCore.Qt.KeepAspectRatio) + def go_to_next_group(self): current_index = self.comboBox_group_select.currentIndex() max_index = self.comboBox_group_select.count() - 1 if current_index < max_index: self.comboBox_group_select.setCurrentIndex(current_index + 1) self.set_group_polygon_visible() + self.zoom_to_group() def go_to_prev_group(self): current_index = self.comboBox_group_select.currentIndex() if current_index > 0: self.comboBox_group_select.setCurrentIndex(current_index - 1) self.set_group_polygon_visible() + self.zoom_to_group() + + From d8aff88092faad4236d1dce1ba25e77ed797a6e6 Mon Sep 17 00:00:00 2001 From: Alias_z Date: Tue, 18 Jul 2023 10:03:37 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E6=94=AF=E6=8C=81group=20id=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E6=95=B0=E5=AD=97=E9=A1=BA=E5=BA=8F=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- widgets/labels_dock_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/labels_dock_widget.py b/widgets/labels_dock_widget.py index f66d196..aa1cde0 100644 --- a/widgets/labels_dock_widget.py +++ b/widgets/labels_dock_widget.py @@ -4,7 +4,7 @@ from PyQt5 import QtWidgets, QtCore, QtGui from ui.label_dock import Ui_Form import functools - +import re class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): def __init__(self, mainwindow): @@ -83,7 +83,7 @@ class LabelsDockWidget(QtWidgets.QWidget, Ui_Form): unique_groups = {polygon.group for polygon in self.mainwindow.polygons} self.comboBox_group_select.clear() self.comboBox_group_select.addItem('All') # add an option to view all groups - self.comboBox_group_select.addItems(sorted(unique_groups)) + self.comboBox_group_select.addItems(sorted(unique_groups, key=lambda s: [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', s)])) def set_selected(self, polygon): item = self.polygon_item_dict[polygon]