Skip to content

Commit

Permalink
enhancements to image navigation and deletion (#115)
Browse files Browse the repository at this point in the history
* bugfixed: resets the selection to the first image after deleting an image

* fixed check-code-style

---------

Co-authored-by: [email protected] <7p=e763wN3A6k+[C>
  • Loading branch information
yes-github authored Nov 21, 2024
1 parent e9accf8 commit 8bb57f1
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -2480,23 +2492,28 @@ 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

if len(self.mImgList) <= 0:
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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8bb57f1

Please sign in to comment.