From 551fc7e00da0c841e165ea4d827b7b11aa4943e8 Mon Sep 17 00:00:00 2001 From: xdzhou Date: Wed, 13 Mar 2019 16:50:53 +0800 Subject: [PATCH] Fix bug: An index error after select a directory when open a new file. --- labelImg.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/labelImg.py b/labelImg.py index dd4856ca..b4cca861 100755 --- a/labelImg.py +++ b/labelImg.py @@ -967,13 +967,19 @@ class MainWindow(QMainWindow, WindowMixin): # Make sure that filePath is a regular python string, rather than QString filePath = ustr(filePath) + # Fix bug: An index error after select a directory when open a new file. unicodeFilePath = ustr(filePath) + unicodeFilePath = os.path.abspath(unicodeFilePath) # Tzutalin 20160906 : Add file list and dock to move faster # Highlight the file item if unicodeFilePath and self.fileListWidget.count() > 0: - index = self.mImgList.index(unicodeFilePath) - fileWidgetItem = self.fileListWidget.item(index) - fileWidgetItem.setSelected(True) + if unicodeFilePath in self.mImgList: + index = self.mImgList.index(unicodeFilePath) + fileWidgetItem = self.fileListWidget.item(index) + fileWidgetItem.setSelected(True) + else: + self.fileListWidget.clear() + self.mImgList.clear() if unicodeFilePath and os.path.exists(unicodeFilePath): if LabelFile.isLabelFile(unicodeFilePath):