Enchance box manipulation and fix CTRL+B bug#255
Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| self.center = QPointF(x, y) | |
| self.center = QPointF(x, y) | |
| else: | |
| self.center = None |
PPOCRLabel.py
Outdated
| shapeFillColor, | ||
| ), | ||
| onLoadActive=(create, createpoly, createMode, editMode), | ||
| onLoadActive=(create, createpoly, createMode, editMode, convertToRect), |
There was a problem hiding this comment.
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.
| onLoadActive=(create, createpoly, createMode, editMode, convertToRect), | |
| onLoadActive=(create, createpoly, createMode, editMode), |
| 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) |
There was a problem hiding this comment.
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.
libs/autoDialog.py
Outdated
| else: | ||
| strs = "" | ||
| for res in self.result_dic: | ||
| # ... (keep existing string formatting) |
There was a problem hiding this comment.
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.
| # ... (keep existing string formatting) | |
| # Build a readable summary line for each OCR result with its text, probability, and location |
Resolves #254