From 8bb57f1efade96db3b976a792953f70af5e53d80 Mon Sep 17 00:00:00 2001 From: Yes Date: Thu, 21 Nov 2024 21:15:43 +0800 Subject: [PATCH] enhancements to image navigation and deletion (#115) * bugfixed: resets the selection to the first image after deleting an image * fixed check-code-style --------- Co-authored-by: aboutibm@163.com <7p=e763wN3A6k+[C> --- PPOCRLabel.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/PPOCRLabel.py b/PPOCRLabel.py index 2a354a0..64a324d 100644 --- a/PPOCRLabel.py +++ b/PPOCRLabel.py @@ -2430,11 +2430,15 @@ def importDirImages(self, dirpath, isDelete=False): ) self.statusBar().show() + imgListCurrIndex = None + if self.filePath != None: + imgListCurrIndex = self.mImgList.index(self.filePath) + self.filePath = None self.fileListWidget.clear() self.mImgList = self.scanAllImages(dirpath) self.mImgList5 = self.mImgList[:5] - self.openNextImg() + self.openNextImg(imgListCurrIndex=imgListCurrIndex) doneicon = newIcon("done") closeicon = newIcon("close") for imgPath in self.mImgList: @@ -2460,7 +2464,15 @@ def importDirImages(self, dirpath, isDelete=False): self.actions.rotateLeft.setEnabled(True) self.actions.rotateRight.setEnabled(True) - self.fileListWidget.setCurrentRow(0) # set list index to first + fileListWidgetCurrentRow = 0 + if imgListCurrIndex is not None: + fileListWidgetCurrentRow = imgListCurrIndex + if fileListWidgetCurrentRow >= self.fileListWidget.count(): + fileListWidgetCurrentRow = fileListWidgetCurrentRow - 1 + + self.fileListWidget.setCurrentRow( + fileListWidgetCurrentRow + ) # set list index to first self.fileDock.setWindowTitle( self.fileListName + f" (1/{self.fileListWidget.count()})" ) # show image count @@ -2480,7 +2492,7 @@ def openPrevImg(self, _value=False): if filename: self.loadFile(filename) - def openNextImg(self, _value=False): + def openNextImg(self, _value=False, imgListCurrIndex=None): if not self.mayContinue(): return @@ -2488,15 +2500,20 @@ def openNextImg(self, _value=False): return filename = None - if self.filePath is None: + if self.filePath is None and imgListCurrIndex is None: filename = self.mImgList[0] self.mImgList5 = self.mImgList[:5] else: - currIndex = self.mImgList.index(self.filePath) + if imgListCurrIndex is None: + currIndex = self.mImgList.index(self.filePath) + else: + currIndex = imgListCurrIndex - 1 + if currIndex + 1 < len(self.mImgList): filename = self.mImgList[currIndex + 1] self.mImgList5 = self.indexTo5Files(currIndex + 1) else: + filename = self.mImgList[currIndex] self.mImgList5 = self.indexTo5Files(currIndex) if filename: print("file name in openNext is ", filename) @@ -2616,8 +2633,6 @@ def deleteImg(self): if imgidx in self.PPlabel.keys(): self.PPlabel.pop(imgidx) - self.filePath = None - self.openNextImg() self.importDirImages(self.lastOpenDir, isDelete=True) def deleteImgDialog(self):