Skip to content

Commit

Permalink
[Feature] Enable move_mode parameter in label_dialog for enhanced int…
Browse files Browse the repository at this point in the history
…eraction control (#558)
  • Loading branch information
CVHub520 committed Jul 31, 2024
1 parent bc05fa0 commit 4a943ad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions anylabeling/configs/xanylabeling_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ file_dock:
# label_dialog
show_label_text_field: true
label_completion: startswith
move_mode: auto # 'auto', 'center'
fit_to_content:
column: true
row: false
Expand Down
7 changes: 6 additions & 1 deletion anylabeling/views/labeling/label_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,7 @@ def edit_label(self, item=None):
description=shape.description,
difficult=shape.difficult,
kie_linking=shape.kie_linking,
move_mode=self._config.get("move_mode", "auto"),
)
if text is None:
return
Expand Down Expand Up @@ -3013,7 +3014,10 @@ def new_shape(self):
description,
difficult,
kie_linking,
) = self.label_dialog.pop_up(text)
) = self.label_dialog.pop_up(
text,
move_mode=self._config.get("move_mode", "auto"),
)
if not text:
self.label_dialog.edit.setText(previous_text)

Expand Down Expand Up @@ -5927,6 +5931,7 @@ def finish_auto_labeling_object(self):
description=None,
difficult=False,
kie_linking=[],
move_mode=self._config.get("move_mode", "auto"),
)
if not text:
self.label_dialog.edit.setText(previous_text)
Expand Down
37 changes: 23 additions & 14 deletions anylabeling/views/labeling/widgets/label_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def pop_up(
self,
text=None,
move=True,
move_mode="auto",
flags=None,
group_id=None,
description=None,
Expand Down Expand Up @@ -724,20 +725,28 @@ def pop_up(
self.edit.setFocus(QtCore.Qt.PopupFocusReason)

if move:
cursor_pos = QtGui.QCursor.pos()
screen = QtWidgets.QApplication.desktop().screenGeometry(
cursor_pos
)
dialog_frame_size = self.frameGeometry()
# Calculate the ideal top-left corner position for the dialog based on the mouse click
ideal_pos = cursor_pos
# Adjust to prevent the dialog from exceeding the right screen boundary
if (ideal_pos.x() + dialog_frame_size.width()) > screen.right():
ideal_pos.setX(screen.right() - dialog_frame_size.width())
# Adjust to prevent the dialog's bottom from going off-screen
if (ideal_pos.y() + dialog_frame_size.height()) > screen.bottom():
ideal_pos.setY(screen.bottom() - dialog_frame_size.height())
self.move(ideal_pos)
if move_mode == "auto":
cursor_pos = QtGui.QCursor.pos()
screen = QtWidgets.QApplication.desktop().screenGeometry(
cursor_pos
)
dialog_frame_size = self.frameGeometry()
# Calculate the ideal top-left corner position for the dialog based on the mouse click
ideal_pos = cursor_pos
# Adjust to prevent the dialog from exceeding the right screen boundary
if (ideal_pos.x() + dialog_frame_size.width()) > screen.right():
ideal_pos.setX(screen.right() - dialog_frame_size.width())
# Adjust to prevent the dialog's bottom from going off-screen
if (ideal_pos.y() + dialog_frame_size.height()) > screen.bottom():
ideal_pos.setY(screen.bottom() - dialog_frame_size.height())
self.move(ideal_pos)
elif move_mode == "center":
# Calculate the center position to move the dialog to
screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos())
centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center()
qr = self.frameGeometry()
qr.moveCenter(centerPoint)
self.move(qr.topLeft())

if self.exec_():
return (
Expand Down

0 comments on commit 4a943ad

Please sign in to comment.