From ac8ba5fc3371b58a5a2d4cfe9cc551963b089015 Mon Sep 17 00:00:00 2001 From: LuGu <2623587501@qq.com> Date: Wed, 28 Jul 2021 21:12:00 +0800 Subject: [PATCH] Update batch move --- PPOCRLabel/PPOCRLabel.py | 15 +++++++-------- PPOCRLabel/libs/canvas.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/PPOCRLabel/PPOCRLabel.py b/PPOCRLabel/PPOCRLabel.py index dd9d7701..8cc4d837 100644 --- a/PPOCRLabel/PPOCRLabel.py +++ b/PPOCRLabel/PPOCRLabel.py @@ -885,16 +885,15 @@ class MainWindow(QMainWindow, WindowMixin): self.updateComboBox() def updateBoxlist(self): + self.canvas.selectedShapes_hShape = [] 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)) + self.canvas.selectedShapes_hShape = self.canvas.selectedShapes + [self.canvas.hShape] 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.canvas.selectedShapes_hShape = self.canvas.selectedShapes + for shape in self.canvas.selectedShapes_hShape: + 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 dbbcca70..c3b7d439 100644 --- a/PPOCRLabel/libs/canvas.py +++ b/PPOCRLabel/libs/canvas.py @@ -23,6 +23,7 @@ except ImportError: from libs.shape import Shape from libs.utils import distance +import copy CURSOR_DEFAULT = Qt.ArrowCursor CURSOR_POINT = Qt.PointingHandCursor @@ -81,6 +82,7 @@ class Canvas(QWidget): self.fourpoint = True # ADD self.pointnum = 0 self.movingShape = False + self.selectCountShape = False #initialisation for panning self.pan_initial_pos = QPoint() @@ -702,6 +704,10 @@ class Canvas(QWidget): def keyPressEvent(self, ev): key = ev.key() + shapesBackup = [] + shapesBackup = copy.deepcopy(self.shapes) + self.shapesBackups.pop() + self.shapesBackups.append(shapesBackup) if key == Qt.Key_Escape and self.current: print('ESC press') self.current = None @@ -720,6 +726,8 @@ class Canvas(QWidget): def moveOnePixel(self, direction): # print(self.selectedShape.points) + self.selectCount = len(self.selectedShapes) + self.selectCountShape = True for i in range(len(self.selectedShapes)): self.selectedShape = self.selectedShapes[i] if direction == 'Left' and not self.moveOutOfBound(QPointF(-1.0, 0)): @@ -746,6 +754,9 @@ class Canvas(QWidget): self.selectedShape.points[1] += QPointF(0, 1.0) self.selectedShape.points[2] += QPointF(0, 1.0) self.selectedShape.points[3] += QPointF(0, 1.0) + shapesBackup = [] + shapesBackup = copy.deepcopy(self.shapes) + self.shapesBackups.append(shapesBackup) self.shapeMoved.emit() self.repaint() @@ -842,6 +853,10 @@ class Canvas(QWidget): def restoreShape(self): if not self.isShapeRestorable: return + if self.selectCountShape: + if len(self.shapesBackups) > 2: + for i in range(1,self.selectCount): + self.shapesBackups.pop() self.shapesBackups.pop() # latest shapesBackup = self.shapesBackups.pop() self.shapes = shapesBackup -- GitLab