From f68f7df702b3d5760e9d5e20e5ffeb1962e93cd3 Mon Sep 17 00:00:00 2001 From: LuGu <2623587501@qq.com> Date: Thu, 22 Jul 2021 14:49:31 +0800 Subject: [PATCH] Update move box --- PPOCRLabel/PPOCRLabel.py | 14 ++++++--- PPOCRLabel/libs/canvas.py | 62 ++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/PPOCRLabel/PPOCRLabel.py b/PPOCRLabel/PPOCRLabel.py index f54542b1..dd9d7701 100644 --- a/PPOCRLabel/PPOCRLabel.py +++ b/PPOCRLabel/PPOCRLabel.py @@ -885,10 +885,16 @@ class MainWindow(QMainWindow, WindowMixin): self.updateComboBox() def updateBoxlist(self): - for shape in self.canvas.selectedShapes+[self.canvas.hShape]: - item = self.shapesToItemsbox[shape] # listitem - text = [(int(p.x()), int(p.y())) for p in shape.points] - item.setText(str(text)) + if self.canvas.hShape != None: + for shape in self.canvas.selectedShapes + [self.canvas.hShape]: + item = self.shapesToItemsbox[shape] # listitem + text = [(int(p.x()), int(p.y())) for p in shape.points] + item.setText(str(text)) + else: + for shape in self.canvas.selectedShapes: + item = self.shapesToItemsbox[shape] # listitem + text = [(int(p.x()), int(p.y())) for p in shape.points] + item.setText(str(text)) self.actions.undo.setEnabled(True) self.setDirty() diff --git a/PPOCRLabel/libs/canvas.py b/PPOCRLabel/libs/canvas.py index 33d20806..dbbcca70 100644 --- a/PPOCRLabel/libs/canvas.py +++ b/PPOCRLabel/libs/canvas.py @@ -709,43 +709,45 @@ class Canvas(QWidget): self.update() elif key == Qt.Key_Return and self.canCloseShape(): self.finalise() - elif key == Qt.Key_Left and self.selectedShape: + elif key == Qt.Key_Left and self.selectedShapes: self.moveOnePixel('Left') - elif key == Qt.Key_Right and self.selectedShape: + elif key == Qt.Key_Right and self.selectedShapes: self.moveOnePixel('Right') - elif key == Qt.Key_Up and self.selectedShape: + elif key == Qt.Key_Up and self.selectedShapes: self.moveOnePixel('Up') - elif key == Qt.Key_Down and self.selectedShape: + elif key == Qt.Key_Down and self.selectedShapes: self.moveOnePixel('Down') def moveOnePixel(self, direction): # print(self.selectedShape.points) - if direction == 'Left' and not self.moveOutOfBound(QPointF(-1.0, 0)): - # print("move Left one pixel") - self.selectedShape.points[0] += QPointF(-1.0, 0) - self.selectedShape.points[1] += QPointF(-1.0, 0) - self.selectedShape.points[2] += QPointF(-1.0, 0) - self.selectedShape.points[3] += QPointF(-1.0, 0) - elif direction == 'Right' and not self.moveOutOfBound(QPointF(1.0, 0)): - # print("move Right one pixel") - self.selectedShape.points[0] += QPointF(1.0, 0) - self.selectedShape.points[1] += QPointF(1.0, 0) - self.selectedShape.points[2] += QPointF(1.0, 0) - self.selectedShape.points[3] += QPointF(1.0, 0) - elif direction == 'Up' and not self.moveOutOfBound(QPointF(0, -1.0)): - # print("move Up one pixel") - self.selectedShape.points[0] += QPointF(0, -1.0) - self.selectedShape.points[1] += QPointF(0, -1.0) - self.selectedShape.points[2] += QPointF(0, -1.0) - self.selectedShape.points[3] += QPointF(0, -1.0) - elif direction == 'Down' and not self.moveOutOfBound(QPointF(0, 1.0)): - # print("move Down one pixel") - self.selectedShape.points[0] += QPointF(0, 1.0) - self.selectedShape.points[1] += QPointF(0, 1.0) - self.selectedShape.points[2] += QPointF(0, 1.0) - self.selectedShape.points[3] += QPointF(0, 1.0) - self.shapeMoved.emit() - self.repaint() + for i in range(len(self.selectedShapes)): + self.selectedShape = self.selectedShapes[i] + if direction == 'Left' and not self.moveOutOfBound(QPointF(-1.0, 0)): + # print("move Left one pixel") + self.selectedShape.points[0] += QPointF(-1.0, 0) + self.selectedShape.points[1] += QPointF(-1.0, 0) + self.selectedShape.points[2] += QPointF(-1.0, 0) + self.selectedShape.points[3] += QPointF(-1.0, 0) + elif direction == 'Right' and not self.moveOutOfBound(QPointF(1.0, 0)): + # print("move Right one pixel") + self.selectedShape.points[0] += QPointF(1.0, 0) + self.selectedShape.points[1] += QPointF(1.0, 0) + self.selectedShape.points[2] += QPointF(1.0, 0) + self.selectedShape.points[3] += QPointF(1.0, 0) + elif direction == 'Up' and not self.moveOutOfBound(QPointF(0, -1.0)): + # print("move Up one pixel") + self.selectedShape.points[0] += QPointF(0, -1.0) + self.selectedShape.points[1] += QPointF(0, -1.0) + self.selectedShape.points[2] += QPointF(0, -1.0) + self.selectedShape.points[3] += QPointF(0, -1.0) + elif direction == 'Down' and not self.moveOutOfBound(QPointF(0, 1.0)): + # print("move Down one pixel") + self.selectedShape.points[0] += QPointF(0, 1.0) + self.selectedShape.points[1] += QPointF(0, 1.0) + self.selectedShape.points[2] += QPointF(0, 1.0) + self.selectedShape.points[3] += QPointF(0, 1.0) + self.shapeMoved.emit() + self.repaint() def moveOutOfBound(self, step): points = [p1+p2 for p1, p2 in zip(self.selectedShape.points, [step]*4)] -- GitLab