Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mini rects detection #49

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/resizable_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(
self.itemSelectedCallback = itemSelectedCallback
self.extraBoxes = []
self.cornerBoxes = []
self.cornerSize = 20
self.cornerSize = 14

self.posItem = QGraphicsSimpleTextItem("{}".format(self.name), parent=self)
self.resultItem = QGraphicsSimpleTextItem("{}".format(self.result), parent=self)
Expand Down Expand Up @@ -243,6 +243,8 @@ def setupAddButton(self):
def setMiniRectMode(self, enabled):
self.mini_rect_mode = enabled
self.add_button.setVisible(enabled)
if not enabled:
self.clearMiniRects()

def setupTextItems(self, image_size, boxDisplayStyle):
self.posItem.setBrush(QBrush(QColor("red")))
Expand Down Expand Up @@ -437,6 +439,10 @@ def startCreateMiniRect(self, rect: QRectF):
)
self.mini_rects.append(new_mini_rect)

def removeMiniRect(self, mini_rect):
self.mini_rects.remove(mini_rect)
self.scene().removeItem(mini_rect)

def clearMiniRects(self):
for mini_rect in self.mini_rects:
self.scene().removeItem(mini_rect)
Expand Down
15 changes: 14 additions & 1 deletion src/source_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from text_detection_target import TextDetectionTarget, TextDetectionTargetWithResult
from sc_logging import logger
from resizable_rect import ResizableRectWithNameTypeAndResult
from resizable_rect import MiniRect, ResizableRectWithNameTypeAndResult


def sort_points_clockwise(points: list[QGraphicsRectItem]) -> list[QGraphicsRectItem]:
Expand Down Expand Up @@ -184,6 +184,19 @@ def selectBox(self, name):
if isinstance(item, ResizableRectWithNameTypeAndResult):
item.setSelected(item.name == name)

def keyPressEvent(self, event):
if event.key() == Qt.Key.Key_Delete:
for item in self.scene.items():
if item.isSelected():
if isinstance(item, MiniRect):
# If there are mini-rects, delete the selected mini-rect
item.parentItem().removeMiniRect(item)
if isinstance(item, ResizableRectWithNameTypeAndResult):
# If no mini-rects, send a signal to delete the box itself
self.removeBox(item.name)
else:
super().keyPressEvent(event)

def mousePressEvent(self, event: QMouseEvent | None) -> None:
if event.button() == Qt.MouseButton.MiddleButton:
self._isPanning = True
Expand Down
Loading