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

修复存在已久的BUG:删除图片后,图片列表跳回选择第一个图片,丢失原来的标记进度 #114

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 23 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,29 @@ 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 +2634,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
Loading