From 3f683939d6c9e386bab67eaafde97957515a6a06 Mon Sep 17 00:00:00 2001 From: cvhub Date: Wed, 10 Jul 2024 10:02:17 +0800 Subject: [PATCH] [Enhancement]: Added confirm button for brightness/contrast adjustments and fixed TypeError in on_new_value method (#511) --- anylabeling/views/labeling/label_widget.py | 4 ++-- .../widgets/brightness_contrast_dialog.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/anylabeling/views/labeling/label_widget.py b/anylabeling/views/labeling/label_widget.py index fd3e0a3b..6bad2afa 100644 --- a/anylabeling/views/labeling/label_widget.py +++ b/anylabeling/views/labeling/label_widget.py @@ -763,7 +763,7 @@ def __init__( enabled=False, ) brightness_contrast = action( - self.tr("&Brightness Contrast"), + self.tr("&Set Brightness Contrast"), self.brightness_contrast, None, "color", @@ -3301,7 +3301,7 @@ def load_file(self, filename=None): # noqa: C901 dialog.slider_contrast.setValue(contrast) self.brightness_contrast_values[self.filename] = (brightness, contrast) if brightness is not None or contrast is not None: - dialog.on_new_value(None) + dialog.on_new_value() self.paint_canvas() self.add_recent_file(self.filename) self.toggle_actions(True) diff --git a/anylabeling/views/labeling/widgets/brightness_contrast_dialog.py b/anylabeling/views/labeling/widgets/brightness_contrast_dialog.py index 207d47c2..0fcddbfd 100644 --- a/anylabeling/views/labeling/widgets/brightness_contrast_dialog.py +++ b/anylabeling/views/labeling/widgets/brightness_contrast_dialog.py @@ -49,11 +49,20 @@ def __init__(self, img, callback, parent=None): self.reset_button = QtWidgets.QPushButton(self.tr("Reset")) self.reset_button.clicked.connect(self.reset_values) + # Confirm button + self.confirm_button = QtWidgets.QPushButton(self.tr("Confirm")) + self.confirm_button.clicked.connect(self.confirm_values) + + # Buttons layout + buttons_layout = QtWidgets.QHBoxLayout() + buttons_layout.addWidget(self.reset_button) + buttons_layout.addWidget(self.confirm_button) + # Main layout main_layout = QtWidgets.QVBoxLayout() main_layout.addWidget(brightness_widget) main_layout.addWidget(contrast_widget) - main_layout.addWidget(self.reset_button) + main_layout.addLayout(buttons_layout) self.setLayout(main_layout) assert isinstance(img, PIL.Image.Image) @@ -90,6 +99,10 @@ def reset_values(self): self.img = self.original_img.copy() self.on_new_value() + def confirm_values(self): + """Confirm the current values and close the dialog""" + self.accept() + def _create_slider(self): """Create brightness/contrast slider""" slider = QtWidgets.QSlider(Qt.Horizontal)