Skip to content

Commit

Permalink
[Enhancement]: Added confirm button for brightness/contrast adjustmen…
Browse files Browse the repository at this point in the history
…ts and fixed TypeError in on_new_value method (#511)
  • Loading branch information
CVHub520 committed Jul 10, 2024
1 parent 607fd87 commit 3f68393
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions anylabeling/views/labeling/label_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion anylabeling/views/labeling/widgets/brightness_contrast_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3f68393

Please sign in to comment.