Skip to content

Enchance box manipulation and fix CTRL+B bug#255

Merged
GreatV merged 2 commits intoPFCCLab:mainfrom
MuhammedOzdogan:feature/254-box-manipulation-enhancement
Mar 29, 2026
Merged

Enchance box manipulation and fix CTRL+B bug#255
GreatV merged 2 commits intoPFCCLab:mainfrom
MuhammedOzdogan:feature/254-box-manipulation-enhancement

Conversation

@MuhammedOzdogan
Copy link
Copy Markdown
Contributor

@MuhammedOzdogan MuhammedOzdogan commented Mar 28, 2026

Resolves #254

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves bounding box manipulation in the PPOCRLabel UI by fixing box resorting behavior (Ctrl+B) and adding a new “convert polygon to rectangle” operation (Ctrl+T), with accompanying UI text/documentation updates.

Changes:

  • Add “Convert to RectBox” action (Ctrl+T) and wire it into menus/selection handling.
  • Rework Ctrl+B “resort box position” to sort using shape geometry (index-based) to handle duplicates more reliably.
  • Update shape center calculation and refresh localized strings/README shortcut tables.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
resources/strings/strings-zh-CN.properties Add localized strings for the new Ctrl+T action.
resources/strings/strings-en.properties Add English strings for the new Ctrl+T action.
libs/utils.py Update shortcut help text to include Ctrl+T.
libs/shape.py Change how Shape.close() computes the center point.
libs/resources.py Regenerated Qt resources blob to include new string entries.
libs/canvas.py Add Ctrl-based symmetric vertex resizing behavior.
libs/autoDialog.py Adjust worker result handling/clearing and simplify “no results” check.
README_ch.md Document Ctrl+T shortcut.
README.md Document Ctrl+T shortcut.
PPOCRLabel.py Add action wiring for Ctrl+T; refactor resort logic; implement convertToRect().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if self.points:
x = sum(p.x() for p in self.points) / len(self.points)
y = sum(p.y() for p in self.points) / len(self.points)
self.center = QPointF(x, y)
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shape.close() no longer resets self.center when self.points is empty. If close() is called after points are cleared, the shape can retain a stale center value, which can break later operations that rely on self.center (e.g., rotations). Consider explicitly setting self.center = None when there are no points.

Suggested change
self.center = QPointF(x, y)
self.center = QPointF(x, y)
else:
self.center = None

Copilot uses AI. Check for mistakes.
PPOCRLabel.py Outdated
shapeFillColor,
),
onLoadActive=(create, createpoly, createMode, editMode),
onLoadActive=(create, createpoly, createMode, editMode, convertToRect),
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convertToRect action is included in onLoadActive, so toggleActions(True) will enable it whenever an image is loaded even when there is no selection. Since the handler no-ops without selectedShapes, this creates an enabled UI action that appears broken. Consider removing it from onLoadActive and relying on shapeSelectionChanged to enable/disable based on selection.

Suggested change
onLoadActive=(create, createpoly, createMode, editMode, convertToRect),
onLoadActive=(create, createpoly, createMode, editMode),

Copilot uses AI. Check for mistakes.
Comment on lines +3969 to +3974
continue

min_x = min(p.x() for p in shape.points)
max_x = max(p.x() for p in shape.points)
min_y = min(p.y() for p in shape.points)
max_y = max(p.y() for p in shape.points)
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertToRect() assumes every selected shape has at least one point. If a selected shape ever has shape.points == [], the min()/max() calls will raise ValueError and crash the action. Add a guard (e.g., skip shapes with no points) before computing bounds.

Copilot uses AI. Check for mistakes.
else:
strs = ""
for res in self.result_dic:
# ... (keep existing string formatting)
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline placeholder comment # ... (keep existing string formatting) is misleading in production code (it reads like code was removed/omitted). Consider deleting it or replacing it with a concrete explanation of the formatting if needed.

Suggested change
# ... (keep existing string formatting)
# Build a readable summary line for each OCR result with its text, probability, and location

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@GreatV GreatV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GreatV GreatV merged commit 2862734 into PFCCLab:main Mar 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature/Bugfix] Enhance box manipulation and fix data integrity/UI synchronization issues

3 participants